Rest Access from javascript using AngularJs
Wednesday, 7 May 2014 · 17 messages · last reply 15 May 2014
YM
Yoann Maingon7 May 2014 01:38 #
Hi,
After xmlprague and my presentation at the BaseX user group I was told (and I agree) that it wasn't really smart to use php for what I was building as it had almost no added value as I could directly query basex using the Rest Interface.
Does anyone as some example using either angularjs or jquery ? I think I'm struggling with the login. Even just trying with a Rest test tool, I can see that I have error messages in Basex telling me theat access was refused.
Yoann Maingon
CEO - mydatalinx
+33664324966
ML
Marco Lettere7 May 2014 09:10 #
Hi Yoann,
we had written an example about two years ago when we were using Openlaszlo (RIP) as GUI tool so my example is in the framework's code. I think it is rather understandable and easily portable to JQuery or any othe AJAX tk.
Following the method for building and sending the request in our OL AJAX class. It sets the src (URI) of the request, the content (with corresponding XML mime type header) taken from a OL dataset and the adds an Authorzation header to the request. The authorization is Basic and is retrieved from a "connectform" widget where the user inserts its credentials.
<method name="sendRequest" args="uri, xmldata">
this.setAttribute("src", connectform.getURL())
this.setHeader("Authorization", connectform.getAuth())
if(xmldata != null){
this.setHeader("Content-Type", "application/xml");
this.setAttribute('postbody', xmldata);
} this.doAJAXRequest()
</method>
This is the connectform.getAuth() method that builds the content of the Basic Authentication Header.
<method name="getAuth">
return "Basic " + b64.encode(this.userfield.getText() + ":"
+ this.passwordfield.getText())
</method>Hope this helps.
Regards,
Marco.
Quoted text · Yoann Maingon · 17 lines
On 05/07/2014 01:38 AM, Yoann Maingon wrote: > Hi, > > After xmlprague and my presentation at the BaseX user group I was told > (and I agree) that it wasn't really smart to use php for what I was > building as it had almost no added value as I could directly query > basex using the Rest Interface. > > Does anyone as some example using either angularjs or jquery ? I think > I'm struggling with the login. Even just trying with a Rest test tool, > I can see that I have error messages in Basex telling me theat access > was refused. > > > Yoann Maingon > CEO - mydatalinx > +33664324966
MG
Hi Yoann,
I guess having examples like these would be helpful in general. Together with basex, we built a larger project for managing conference registrations etc. last year. I could extract some of the modules - maybe we could manage to publish them on some github repo or a dedicated site? @basex: maybe it is time for a basex contrib page?
What you need, is some json endpoint which leverages the session module, checks the credentials and returns some json back to Angular (or JQuey)
Besides that, you need to secure all your restxq endpoints with a authentication check:
if(not(session:logged-in())) then
web:redirect($C:START-PAGE) else _:do-something-useful()
Login example:
import module namespace session = "http://basex.org/modules/web/session";
declare
%restxq:path("/api/login/check")
%restxq:POST("{$content}")
%output:method("json")
%output:json("lax=yes")
function _:check(
$content as item()*
)
{
let $user := $content//u/string()
let $pass := $content//p/string() let $ok := _:check-user($user, $pass)
if ($ok) then
let $user-id := session:id()
let $role := session:role()
return((),
<json objects="json">
<url>{_:redirect-url-from-role($role)}</url>
</json>
)
else
<json objects="json">
<error>Login failed.</error>
</json>
};
angular.module('login', [])
.config([
'$routeProvider',
function ($routeProvider) {
$routeProvider.when('/Logout', {
redirectTo: '/restxq/logout'
});
}])
.controller('LoginCtrl', [
'$scope', '$http', '$location',
function ($scope, $http, $location) {
$scope.login = function() {
var url = '/restxq/api/login/check';
//use jquery here, because angular does not detect auto-fill data
var payload = {
u: $('#u').val(),
p: $('#p').val()
};
$http.post(url, payload).
success(function(data) {
if (data.error) {
// trigger error status
$scope.loginForm.$error.failed = true;
} else {
// redirect
window.location.pathname = data.url;
}
}).
error(function(data, status, headers, config) {
alert("Could not load data from server.")
});
};
}]);
<div class="row" ng-controller="LoginCtrl">
<div class="span6 offset3">
<h2 class="alumni-name">Please Login</h2>
<div class="alert alert-error" ng-show="loginForm.$error.failed">
<p>
Incorrect login data. Please try again.
</p>
</div>
<form name="loginForm">
<table cellpadding="3">
<tr>
<td>Username  </td>
<td><input type="text" name="u" id="u" ng-model="user"
style="width:146px !important;margin:0"/></td>
</tr>
<tr>
<td>Password   </td>
<td><input id="p" name="p" ng-model="password"
style="width:146px !important;margin:0" type="password" /></td>
</tr>
<tr>
<td/>
<td><button ng-click="login()" class="btn"
style="width:152px !important;margin:0">Login</button>
</td>
</tr>
</table>
</form>
</div>
</div> Regards,
Max
2014-05-07 1:38 GMT+02:00 Yoann Maingon <yoann.maingon at mydatalinx.com>:
Quoted text · Yoann Maingon · 15 lines
> Hi, > > After xmlprague and my presentation at the BaseX user group I was told (and > I agree) that it wasn't really smart to use php for what I was building as > it had almost no added value as I could directly query basex using the Rest > Interface. > > Does anyone as some example using either angularjs or jquery ? I think I'm > struggling with the login. Even just trying with a Rest test tool, I can see > that I have error messages in Basex telling me theat access was refused. > > > Yoann Maingon > CEO - mydatalinx > +33664324966
DK
Dirk Kirsten7 May 2014 10:18 #
Hi,
I agree with Max that it would be a good idea to have a list of projects and examples, which are build on top of BaseX. A problem might be that many applications which are build on top of BaseX are not open source.
@Yoann: Please be aware that there is a Rest and RestXQ implementation within BaseX, which are quite different. What you most likely want to use is RestXQ. Some documentation is available at
https://docs.basex.org/wiki/RESTXQ
Using RestXQ itself, there is an example for a blog at
https://github.com/siserle/blog-example
As Max already suggested, the main difference when you use it with angular or some other framework is that you most likely want to return JSON, so you have to change the output method.
Cheers,
Dirk
Quoted text · Maximilian Gärber · 147 lines
On 07/05/14 09:34, Maximilian Gärber wrote: > Hi Yoann, > > I guess having examples like these would be helpful in general. > Together with basex, we built a larger project for managing conference > registrations etc. last year. I could extract some of the modules - > maybe we could manage to publish them on some github repo or a > dedicated site? @basex: maybe it is time for a basex contrib page? > > What you need, is some json endpoint which leverages the session > module, checks the credentials and returns some json back to Angular > (or JQuey) > > Besides that, you need to secure all your restxq endpoints with a > authentication check: > > if(not(session:logged-in())) then web:redirect($C:START-PAGE) else > _:do-something-useful() > > > Login example: > > > import module namespace session = "http://basex.org/modules/web/session"; > > declare > %restxq:path("/api/login/check") > %restxq:POST("{$content}") > %output:method("json") > %output:json("lax=yes") > function _:check( > $content as item()* > ) > { > let $user := $content//u/string() > let $pass := $content//p/string() > > let $ok := _:check-user($user, $pass) > > if ($ok) then > let $user-id := session:id() > let $role := session:role() > return((), > <json objects="json"> > <url>{_:redirect-url-from-role($role)}</url> > </json> > ) > else > <json objects="json"> > <error>Login failed.</error> > </json> > }; > > > angular.module('login', []) > .config([ > '$routeProvider', > function ($routeProvider) { > $routeProvider.when('/Logout', { > redirectTo: '/restxq/logout' > }); > }]) > > .controller('LoginCtrl', [ > '$scope', '$http', '$location', > function ($scope, $http, $location) { > $scope.login = function() { > var url = '/restxq/api/login/check'; > > //use jquery here, because angular does not detect auto-fill data > var payload = { > u: $('#u').val(), > p: $('#p').val() > }; > > $http.post(url, payload). > success(function(data) { > if (data.error) { > // trigger error status > $scope.loginForm.$error.failed = true; > } else { > // redirect > window.location.pathname = data.url; > } > }). > error(function(data, status, headers, config) { > alert("Could not load data from server.") > }); > }; > }]); > > <div class="row" ng-controller="LoginCtrl"> > <div class="span6 offset3"> > <h2 class="alumni-name">Please Login</h2> > > <div class="alert alert-error" ng-show="loginForm.$error.failed"> > <p> > Incorrect login data. Please try again. > </p> > </div> > <form name="loginForm"> > <table cellpadding="3"> > <tr> > <td>Username  </td> > <td><input type="text" name="u" id="u" ng-model="user" > style="width:146px !important;margin:0"/></td> > </tr> > <tr> > <td>Password   </td> > <td><input id="p" name="p" ng-model="password" > style="width:146px !important;margin:0" type="password" /></td> > </tr> > <tr> > <td/> > <td><button ng-click="login()" class="btn" > style="width:152px !important;margin:0">Login</button> > </td> > </tr> > </table> > > </form> > </div> > </div> > > Regards, > > Max > > > > > 2014-05-07 1:38 GMT+02:00 Yoann Maingon <yoann.maingon at mydatalinx.com>: >> Hi, >> >> After xmlprague and my presentation at the BaseX user group I was told (and >> I agree) that it wasn't really smart to use php for what I was building as >> it had almost no added value as I could directly query basex using the Rest >> Interface. >> >> Does anyone as some example using either angularjs or jquery ? I think I'm >> struggling with the login. Even just trying with a Rest test tool, I can see >> that I have error messages in Basex telling me theat access was refused. >> >> >> Yoann Maingon >> CEO - mydatalinx >> +33664324966
--
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
YM
Yoann Maingon7 May 2014 10:44 #
Thx
I look into the provided example. At first I was more going into Rest and not RestXq, but if I need to do so then I guess I need to spend some time on it.
Open sourcing our projects is a good question.
I still have some colleagues affraid to somehow loose what they've developped and I don't have a clear opinion about it. But I'd be happy to share code (you may regret it! I'm a bad developper !)
*Cordialement / Best Regards,*
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-07 10:18 GMT+02:00 Dirk Kirsten <dk at basex.org>:
Quoted text · Dirk Kirsten · 181 lines
> Hi, > > I agree with Max that it would be a good idea to have a list of projects > and examples, which are build on top of BaseX. A problem might be that > many applications which are build on top of BaseX are not open source. > > @Yoann: Please be aware that there is a Rest and RestXQ implementation > within BaseX, which are quite different. What you most likely want to > use is RestXQ. Some documentation is available at > https://docs.basex.org/wiki/RESTXQ > Using RestXQ itself, there is an example for a blog at > https://github.com/siserle/blog-example > > As Max already suggested, the main difference when you use it with > angular or some other framework is that you most likely want to return > JSON, so you have to change the output method. > > Cheers, > Dirk > > On 07/05/14 09:34, Maximilian Gärber wrote: > > Hi Yoann, > > > > I guess having examples like these would be helpful in general. > > Together with basex, we built a larger project for managing conference > > registrations etc. last year. I could extract some of the modules - > > maybe we could manage to publish them on some github repo or a > > dedicated site? @basex: maybe it is time for a basex contrib page? > > > > What you need, is some json endpoint which leverages the session > > module, checks the credentials and returns some json back to Angular > > (or JQuey) > > > > Besides that, you need to secure all your restxq endpoints with a > > authentication check: > > > > if(not(session:logged-in())) then web:redirect($C:START-PAGE) else > > _:do-something-useful() > > > > > > Login example: > > > > > > import module namespace session = "http://basex.org/modules/web/session > "; > > > > declare > > %restxq:path("/api/login/check") > > %restxq:POST("{$content}") > > %output:method("json") > > %output:json("lax=yes") > > function _:check( > > $content as item()* > > ) > > { > > let $user := $content//u/string() > > let $pass := $content//p/string() > > > > let $ok := _:check-user($user, $pass) > > > > if ($ok) then > > let $user-id := session:id() > > let $role := session:role() > > return((), > > <json objects="json"> > > <url>{_:redirect-url-from-role($role)}</url> > > </json> > > ) > > else > > <json objects="json"> > > <error>Login failed.</error> > > </json> > > }; > > > > > > angular.module('login', []) > > .config([ > > '$routeProvider', > > function ($routeProvider) { > > $routeProvider.when('/Logout', { > > redirectTo: '/restxq/logout' > > }); > > }]) > > > > .controller('LoginCtrl', [ > > '$scope', '$http', '$location', > > function ($scope, $http, $location) { > > $scope.login = function() { > > var url = '/restxq/api/login/check'; > > > > //use jquery here, because angular does not detect auto-fill data > > var payload = { > > u: $('#u').val(), > > p: $('#p').val() > > }; > > > > $http.post(url, payload). > > success(function(data) { > > if (data.error) { > > // trigger error status > > $scope.loginForm.$error.failed = true; > > } else { > > // redirect > > window.location.pathname = data.url; > > } > > }). > > error(function(data, status, headers, config) { > > alert("Could not load data from server.") > > }); > > }; > > }]); > > > > <div class="row" ng-controller="LoginCtrl"> > > <div class="span6 offset3"> > > <h2 class="alumni-name">Please Login</h2> > > > > <div class="alert alert-error" ng-show="loginForm.$error.failed"> > > <p> > > Incorrect login data. Please try again. > > </p> > > </div> > > <form name="loginForm"> > > <table cellpadding="3"> > > <tr> > > <td>Username  </td> > > <td><input type="text" name="u" id="u" ng-model="user" > > style="width:146px !important;margin:0"/></td> > > </tr> > > <tr> > > <td>Password   </td> > > <td><input id="p" name="p" ng-model="password" > > style="width:146px !important;margin:0" type="password" /></td> > > </tr> > > <tr> > > <td/> > > <td><button ng-click="login()" class="btn" > > style="width:152px !important;margin:0">Login</button> > > </td> > > </tr> > > </table> > > > > </form> > > </div> > > </div> > > > > Regards, > > > > Max > > > > > > > > > > 2014-05-07 1:38 GMT+02:00 Yoann Maingon <yoann.maingon at mydatalinx.com>: > >> Hi, > >> > >> After xmlprague and my presentation at the BaseX user group I was told > (and > >> I agree) that it wasn't really smart to use php for what I was building > as > >> it had almost no added value as I could directly query basex using the > Rest > >> Interface. > >> > >> Does anyone as some example using either angularjs or jquery ? I think > I'm > >> struggling with the login. Even just trying with a Rest test tool, I > can see > >> that I have error messages in Basex telling me theat access was refused. > >> > >> > >> Yoann Maingon > >> CEO - mydatalinx > >> +33664324966 > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >
DK
Dirk Kirsten7 May 2014 11:06 #
Hello Yoann,
You do not "need to do so", but I remember your project quite well and I was one of the people who said you don't actually need PHP. From what I saw and remember, I think RestXQ is simply a much better fit.
RestXQ enables you to do complete server-side processing (just like PHP does) using XQuery. You can define all sorts of options for your functions using annotations and how it should be served to your users.
Theoretically, this would also be possible using Rest. However, the Rest interface is more intended for short queries and querying on a data set. You will always have to submit your query and of course this is very impractical and slow if you develop a whole web app.
But it might be a good idea to add something to the documentation to make the distinction between rest and RestXQ clearer. So much we could add to the docs, actually... :)
Cheers,
Dirk
Quoted text · Yoann Maingon · 209 lines
On 07/05/14 10:44, Yoann Maingon wrote: > Thx > > I look into the provided example. At first I was more going into Rest and > not RestXq, but if I need to do so then I guess I need to spend some time > on it. > Open sourcing our projects is a good question. > I still have some colleagues affraid to somehow loose what they've > developped and I don't have a clear opinion about it. But I'd be happy to > share code (you may regret it! I'm a bad developper !) > > > *Cordialement / Best Regards,* > > *Yoann Maingon* > Minerva France > > *+33 6 64 32 49 66* > > Download Aras Innovator - Téléchargez Aras > Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> > > > > > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten <dk at basex.org>: > >> Hi, >> >> I agree with Max that it would be a good idea to have a list of projects >> and examples, which are build on top of BaseX. A problem might be that >> many applications which are build on top of BaseX are not open source. >> >> @Yoann: Please be aware that there is a Rest and RestXQ implementation >> within BaseX, which are quite different. What you most likely want to >> use is RestXQ. Some documentation is available at >> https://docs.basex.org/wiki/RESTXQ >> Using RestXQ itself, there is an example for a blog at >> https://github.com/siserle/blog-example >> >> As Max already suggested, the main difference when you use it with >> angular or some other framework is that you most likely want to return >> JSON, so you have to change the output method. >> >> Cheers, >> Dirk >> >> On 07/05/14 09:34, Maximilian Gärber wrote: >>> Hi Yoann, >>> >>> I guess having examples like these would be helpful in general. >>> Together with basex, we built a larger project for managing conference >>> registrations etc. last year. I could extract some of the modules - >>> maybe we could manage to publish them on some github repo or a >>> dedicated site? @basex: maybe it is time for a basex contrib page? >>> >>> What you need, is some json endpoint which leverages the session >>> module, checks the credentials and returns some json back to Angular >>> (or JQuey) >>> >>> Besides that, you need to secure all your restxq endpoints with a >>> authentication check: >>> >>> if(not(session:logged-in())) then web:redirect($C:START-PAGE) else >>> _:do-something-useful() >>> >>> >>> Login example: >>> >>> >>> import module namespace session = "http://basex.org/modules/web/session >> "; >>> >>> declare >>> %restxq:path("/api/login/check") >>> %restxq:POST("{$content}") >>> %output:method("json") >>> %output:json("lax=yes") >>> function _:check( >>> $content as item()* >>> ) >>> { >>> let $user := $content//u/string() >>> let $pass := $content//p/string() >>> >>> let $ok := _:check-user($user, $pass) >>> >>> if ($ok) then >>> let $user-id := session:id() >>> let $role := session:role() >>> return((), >>> <json objects="json"> >>> <url>{_:redirect-url-from-role($role)}</url> >>> </json> >>> ) >>> else >>> <json objects="json"> >>> <error>Login failed.</error> >>> </json> >>> }; >>> >>> >>> angular.module('login', []) >>> .config([ >>> '$routeProvider', >>> function ($routeProvider) { >>> $routeProvider.when('/Logout', { >>> redirectTo: '/restxq/logout' >>> }); >>> }]) >>> >>> .controller('LoginCtrl', [ >>> '$scope', '$http', '$location', >>> function ($scope, $http, $location) { >>> $scope.login = function() { >>> var url = '/restxq/api/login/check'; >>> >>> //use jquery here, because angular does not detect auto-fill data >>> var payload = { >>> u: $('#u').val(), >>> p: $('#p').val() >>> }; >>> >>> $http.post(url, payload). >>> success(function(data) { >>> if (data.error) { >>> // trigger error status >>> $scope.loginForm.$error.failed = true; >>> } else { >>> // redirect >>> window.location.pathname = data.url; >>> } >>> }). >>> error(function(data, status, headers, config) { >>> alert("Could not load data from server.") >>> }); >>> }; >>> }]); >>> >>> <div class="row" ng-controller="LoginCtrl"> >>> <div class="span6 offset3"> >>> <h2 class="alumni-name">Please Login</h2> >>> >>> <div class="alert alert-error" ng-show="loginForm.$error.failed"> >>> <p> >>> Incorrect login data. Please try again. >>> </p> >>> </div> >>> <form name="loginForm"> >>> <table cellpadding="3"> >>> <tr> >>> <td>Username  </td> >>> <td><input type="text" name="u" id="u" ng-model="user" >>> style="width:146px !important;margin:0"/></td> >>> </tr> >>> <tr> >>> <td>Password   </td> >>> <td><input id="p" name="p" ng-model="password" >>> style="width:146px !important;margin:0" type="password" /></td> >>> </tr> >>> <tr> >>> <td/> >>> <td><button ng-click="login()" class="btn" >>> style="width:152px !important;margin:0">Login</button> >>> </td> >>> </tr> >>> </table> >>> >>> </form> >>> </div> >>> </div> >>> >>> Regards, >>> >>> Max >>> >>> >>> >>> >>> 2014-05-07 1:38 GMT+02:00 Yoann Maingon <yoann.maingon at mydatalinx.com>: >>>> Hi, >>>> >>>> After xmlprague and my presentation at the BaseX user group I was told >> (and >>>> I agree) that it wasn't really smart to use php for what I was building >> as >>>> it had almost no added value as I could directly query basex using the >> Rest >>>> Interface. >>>> >>>> Does anyone as some example using either angularjs or jquery ? I think >> I'm >>>> struggling with the login. Even just trying with a Rest test tool, I >> can see >>>> that I have error messages in Basex telling me theat access was refused. >>>> >>>> >>>> Yoann Maingon >>>> CEO - mydatalinx >>>> +33664324966 >> >> -- >> Dirk Kirsten, BaseX GmbH, http://basex.org >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >> >
--
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
AB
Andy Bunce7 May 2014 12:02 #
Hi Yoann,
I completely agree that RESTXQ is the way to go. I have some Angular auth code for RESTXQ similar to Maximilian's [1]. This is a bit old now (BaseX 7.5 Angular 1.0) so may have rotted a bit.
However one thing to be aware of with the current implementation is that response times depend on the quantity of XQuery code defined, making large applications problematic. This was mentioned in Christian's recent "Upcoming features" email, so I am sure it will be addressed soon.
Regards
/Andy
[1]
https://github.com/apb2006/basex-cellar/blob/master/src/cellar/auth/auth.js
Quoted text · Dirk Kirsten · 244 lines
On 7 May 2014 10:06, Dirk Kirsten <dk at basex.org> wrote: > Hello Yoann, > > You do not "need to do so", but I remember your project quite well and I > was one of the people who said you don't actually need PHP. From what I > saw and remember, I think RestXQ is simply a much better fit. > > RestXQ enables you to do complete server-side processing (just like PHP > does) using XQuery. You can define all sorts of options for your > functions using annotations and how it should be served to your users. > > Theoretically, this would also be possible using Rest. However, the Rest > interface is more intended for short queries and querying on a data set. > You will always have to submit your query and of course this is very > impractical and slow if you develop a whole web app. > But it might be a good idea to add something to the documentation to > make the distinction between rest and RestXQ clearer. So much we could > add to the docs, actually... :) > > Cheers, > Dirk > > On 07/05/14 10:44, Yoann Maingon wrote: > > Thx > > > > I look into the provided example. At first I was more going into Rest and > > not RestXq, but if I need to do so then I guess I need to spend some time > > on it. > > Open sourcing our projects is a good question. > > I still have some colleagues affraid to somehow loose what they've > > developped and I don't have a clear opinion about it. But I'd be happy to > > share code (you may regret it! I'm a bad developper !) > > > > > > *Cordialement / Best Regards,* > > > > *Yoann Maingon* > > Minerva France > > > > *+33 6 64 32 49 66* > > > > Download Aras Innovator - Téléchargez Aras > > Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> > > > > > > > > > > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten <dk at basex.org>: > > > >> Hi, > >> > >> I agree with Max that it would be a good idea to have a list of projects > >> and examples, which are build on top of BaseX. A problem might be that > >> many applications which are build on top of BaseX are not open source. > >> > >> @Yoann: Please be aware that there is a Rest and RestXQ implementation > >> within BaseX, which are quite different. What you most likely want to > >> use is RestXQ. Some documentation is available at > >> https://docs.basex.org/wiki/RESTXQ > >> Using RestXQ itself, there is an example for a blog at > >> https://github.com/siserle/blog-example > >> > >> As Max already suggested, the main difference when you use it with > >> angular or some other framework is that you most likely want to return > >> JSON, so you have to change the output method. > >> > >> Cheers, > >> Dirk > >> > >> On 07/05/14 09:34, Maximilian Gärber wrote: > >>> Hi Yoann, > >>> > >>> I guess having examples like these would be helpful in general. > >>> Together with basex, we built a larger project for managing conference > >>> registrations etc. last year. I could extract some of the modules - > >>> maybe we could manage to publish them on some github repo or a > >>> dedicated site? @basex: maybe it is time for a basex contrib page? > >>> > >>> What you need, is some json endpoint which leverages the session > >>> module, checks the credentials and returns some json back to Angular > >>> (or JQuey) > >>> > >>> Besides that, you need to secure all your restxq endpoints with a > >>> authentication check: > >>> > >>> if(not(session:logged-in())) then web:redirect($C:START-PAGE) else > >>> _:do-something-useful() > >>> > >>> > >>> Login example: > >>> > >>> > >>> import module namespace session = " > http://basex.org/modules/web/session > >> "; > >>> > >>> declare > >>> %restxq:path("/api/login/check") > >>> %restxq:POST("{$content}") > >>> %output:method("json") > >>> %output:json("lax=yes") > >>> function _:check( > >>> $content as item()* > >>> ) > >>> { > >>> let $user := $content//u/string() > >>> let $pass := $content//p/string() > >>> > >>> let $ok := _:check-user($user, $pass) > >>> > >>> if ($ok) then > >>> let $user-id := session:id() > >>> let $role := session:role() > >>> return((), > >>> <json objects="json"> > >>> <url>{_:redirect-url-from-role($role)}</url> > >>> </json> > >>> ) > >>> else > >>> <json objects="json"> > >>> <error>Login failed.</error> > >>> </json> > >>> }; > >>> > >>> > >>> angular.module('login', []) > >>> .config([ > >>> '$routeProvider', > >>> function ($routeProvider) { > >>> $routeProvider.when('/Logout', { > >>> redirectTo: '/restxq/logout' > >>> }); > >>> }]) > >>> > >>> .controller('LoginCtrl', [ > >>> '$scope', '$http', '$location', > >>> function ($scope, $http, $location) { > >>> $scope.login = function() { > >>> var url = '/restxq/api/login/check'; > >>> > >>> //use jquery here, because angular does not detect auto-fill > data > >>> var payload = { > >>> u: $('#u').val(), > >>> p: $('#p').val() > >>> }; > >>> > >>> $http.post(url, payload). > >>> success(function(data) { > >>> if (data.error) { > >>> // trigger error status > >>> $scope.loginForm.$error.failed = true; > >>> } else { > >>> // redirect > >>> window.location.pathname = data.url; > >>> } > >>> }). > >>> error(function(data, status, headers, config) { > >>> alert("Could not load data from server.") > >>> }); > >>> }; > >>> }]); > >>> > >>> <div class="row" ng-controller="LoginCtrl"> > >>> <div class="span6 offset3"> > >>> <h2 class="alumni-name">Please Login</h2> > >>> > >>> <div class="alert alert-error" ng-show="loginForm.$error.failed"> > >>> <p> > >>> Incorrect login data. Please try again. > >>> </p> > >>> </div> > >>> <form name="loginForm"> > >>> <table cellpadding="3"> > >>> <tr> > >>> <td>Username  </td> > >>> <td><input type="text" name="u" id="u" ng-model="user" > >>> style="width:146px !important;margin:0"/></td> > >>> </tr> > >>> <tr> > >>> <td>Password   </td> > >>> <td><input id="p" name="p" ng-model="password" > >>> style="width:146px !important;margin:0" type="password" /></td> > >>> </tr> > >>> <tr> > >>> <td/> > >>> <td><button ng-click="login()" class="btn" > >>> style="width:152px !important;margin:0">Login</button> > >>> </td> > >>> </tr> > >>> </table> > >>> > >>> </form> > >>> </div> > >>> </div> > >>> > >>> Regards, > >>> > >>> Max > >>> > >>> > >>> > >>> > >>> 2014-05-07 1:38 GMT+02:00 Yoann Maingon <yoann.maingon at mydatalinx.com > >: > >>>> Hi, > >>>> > >>>> After xmlprague and my presentation at the BaseX user group I was told > >> (and > >>>> I agree) that it wasn't really smart to use php for what I was > building > >> as > >>>> it had almost no added value as I could directly query basex using the > >> Rest > >>>> Interface. > >>>> > >>>> Does anyone as some example using either angularjs or jquery ? I think > >> I'm > >>>> struggling with the login. Even just trying with a Rest test tool, I > >> can see > >>>> that I have error messages in Basex telling me theat access was > refused. > >>>> > >>>> > >>>> Yoann Maingon > >>>> CEO - mydatalinx > >>>> +33664324966 > >> > >> -- > >> Dirk Kirsten, BaseX GmbH, http://basex.org > >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > >> > > > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >
CG
Christian Grün7 May 2014 12:24 #
Quoted text · Andy Bunce · 4 lines
> However one thing to be aware of with the current implementation is that > response times depend on the quantity of XQuery code defined, making large > applications problematic. This was mentioned in Christian's recent "Upcoming > features" email, so I am sure it will be addressed soon.
I agree with Andy (although I was surprised about the reported execution times at that time). In one of our projects, we now have around 500 KB of XQuery code, and the constant overhead for evaluating a single REST request is about 40 ms - which may be too slow if you have lots of requests per seconds.
However, if you encounter bottlenecks, there are already various ways to improve performance (all of them undocumented, I guess - once again, Wiki edits are welcome..):
* Move all XQuery modules without RESTXQ annotations into your repository ("repo" directory) [1]. This can be done manually (there is no need to use the REPO commands), and you can edit XQuery modules directly in your repo directory.
* Only keep those XQuery modules in your restxq directory which are required in your project.
The reason is that the restxq directory is scanned for changes every time a new request takes place. We think about introducing a RELEASE mode in a future version, in which various checks will be skipped that are required during the development stage.
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/Repository
Quoted text · Andy Bunce · 252 lines
>> Hello Yoann, >> >> You do not "need to do so", but I remember your project quite well and I >> was one of the people who said you don't actually need PHP. From what I >> saw and remember, I think RestXQ is simply a much better fit. >> >> RestXQ enables you to do complete server-side processing (just like PHP >> does) using XQuery. You can define all sorts of options for your >> functions using annotations and how it should be served to your users. >> >> Theoretically, this would also be possible using Rest. However, the Rest >> interface is more intended for short queries and querying on a data set. >> You will always have to submit your query and of course this is very >> impractical and slow if you develop a whole web app. >> But it might be a good idea to add something to the documentation to >> make the distinction between rest and RestXQ clearer. So much we could >> add to the docs, actually... :) >> >> Cheers, >> Dirk >> >> On 07/05/14 10:44, Yoann Maingon wrote: >> > Thx >> > >> > I look into the provided example. At first I was more going into Rest >> > and >> > not RestXq, but if I need to do so then I guess I need to spend some >> > time >> > on it. >> > Open sourcing our projects is a good question. >> > I still have some colleagues affraid to somehow loose what they've >> > developped and I don't have a clear opinion about it. But I'd be happy >> > to >> > share code (you may regret it! I'm a bad developper !) >> > >> > >> > *Cordialement / Best Regards,* >> > >> > *Yoann Maingon* >> > Minerva France >> > >> > *+33 6 64 32 49 66* >> > >> > Download Aras Innovator - Téléchargez Aras >> > Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> >> > >> > >> > >> > >> > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten <dk at basex.org>: >> > >> >> Hi, >> >> >> >> I agree with Max that it would be a good idea to have a list of >> >> projects >> >> and examples, which are build on top of BaseX. A problem might be that >> >> many applications which are build on top of BaseX are not open source. >> >> >> >> @Yoann: Please be aware that there is a Rest and RestXQ implementation >> >> within BaseX, which are quite different. What you most likely want to >> >> use is RestXQ. Some documentation is available at >> >> https://docs.basex.org/wiki/RESTXQ >> >> Using RestXQ itself, there is an example for a blog at >> >> https://github.com/siserle/blog-example >> >> >> >> As Max already suggested, the main difference when you use it with >> >> angular or some other framework is that you most likely want to return >> >> JSON, so you have to change the output method. >> >> >> >> Cheers, >> >> Dirk >> >> >> >> On 07/05/14 09:34, Maximilian Gärber wrote: >> >>> Hi Yoann, >> >>> >> >>> I guess having examples like these would be helpful in general. >> >>> Together with basex, we built a larger project for managing conference >> >>> registrations etc. last year. I could extract some of the modules - >> >>> maybe we could manage to publish them on some github repo or a >> >>> dedicated site? @basex: maybe it is time for a basex contrib page? >> >>> >> >>> What you need, is some json endpoint which leverages the session >> >>> module, checks the credentials and returns some json back to Angular >> >>> (or JQuey) >> >>> >> >>> Besides that, you need to secure all your restxq endpoints with a >> >>> authentication check: >> >>> >> >>> if(not(session:logged-in())) then web:redirect($C:START-PAGE) else >> >>> _:do-something-useful() >> >>> >> >>> >> >>> Login example: >> >>> >> >>> >> >>> import module namespace session = >> >>> "http://basex.org/modules/web/session >> >> "; >> >>> >> >>> declare >> >>> %restxq:path("/api/login/check") >> >>> %restxq:POST("{$content}") >> >>> %output:method("json") >> >>> %output:json("lax=yes") >> >>> function _:check( >> >>> $content as item()* >> >>> ) >> >>> { >> >>> let $user := $content//u/string() >> >>> let $pass := $content//p/string() >> >>> >> >>> let $ok := _:check-user($user, $pass) >> >>> >> >>> if ($ok) then >> >>> let $user-id := session:id() >> >>> let $role := session:role() >> >>> return((), >> >>> <json objects="json"> >> >>> <url>{_:redirect-url-from-role($role)}</url> >> >>> </json> >> >>> ) >> >>> else >> >>> <json objects="json"> >> >>> <error>Login failed.</error> >> >>> </json> >> >>> }; >> >>> >> >>> >> >>> angular.module('login', []) >> >>> .config([ >> >>> '$routeProvider', >> >>> function ($routeProvider) { >> >>> $routeProvider.when('/Logout', { >> >>> redirectTo: '/restxq/logout' >> >>> }); >> >>> }]) >> >>> >> >>> .controller('LoginCtrl', [ >> >>> '$scope', '$http', '$location', >> >>> function ($scope, $http, $location) { >> >>> $scope.login = function() { >> >>> var url = '/restxq/api/login/check'; >> >>> >> >>> //use jquery here, because angular does not detect auto-fill >> >>> data >> >>> var payload = { >> >>> u: $('#u').val(), >> >>> p: $('#p').val() >> >>> }; >> >>> >> >>> $http.post(url, payload). >> >>> success(function(data) { >> >>> if (data.error) { >> >>> // trigger error status >> >>> $scope.loginForm.$error.failed = true; >> >>> } else { >> >>> // redirect >> >>> window.location.pathname = data.url; >> >>> } >> >>> }). >> >>> error(function(data, status, headers, config) { >> >>> alert("Could not load data from server.") >> >>> }); >> >>> }; >> >>> }]); >> >>> >> >>> <div class="row" ng-controller="LoginCtrl"> >> >>> <div class="span6 offset3"> >> >>> <h2 class="alumni-name">Please Login</h2> >> >>> >> >>> <div class="alert alert-error" >> >>> ng-show="loginForm.$error.failed"> >> >>> <p> >> >>> Incorrect login data. Please try again. >> >>> </p> >> >>> </div> >> >>> <form name="loginForm"> >> >>> <table cellpadding="3"> >> >>> <tr> >> >>> <td>Username  </td> >> >>> <td><input type="text" name="u" id="u" ng-model="user" >> >>> style="width:146px !important;margin:0"/></td> >> >>> </tr> >> >>> <tr> >> >>> <td>Password   </td> >> >>> <td><input id="p" name="p" ng-model="password" >> >>> style="width:146px !important;margin:0" type="password" /></td> >> >>> </tr> >> >>> <tr> >> >>> <td/> >> >>> <td><button ng-click="login()" class="btn" >> >>> style="width:152px !important;margin:0">Login</button> >> >>> </td> >> >>> </tr> >> >>> </table> >> >>> >> >>> </form> >> >>> </div> >> >>> </div> >> >>> >> >>> Regards, >> >>> >> >>> Max >> >>> >> >>> >> >>> >> >>> >> >>> 2014-05-07 1:38 GMT+02:00 Yoann Maingon >> >>> <yoann.maingon at mydatalinx.com>: >> >>>> Hi, >> >>>> >> >>>> After xmlprague and my presentation at the BaseX user group I was >> >>>> told >> >> (and >> >>>> I agree) that it wasn't really smart to use php for what I was >> >>>> building >> >> as >> >>>> it had almost no added value as I could directly query basex using >> >>>> the >> >> Rest >> >>>> Interface. >> >>>> >> >>>> Does anyone as some example using either angularjs or jquery ? I >> >>>> think >> >> I'm >> >>>> struggling with the login. Even just trying with a Rest test tool, I >> >> can see >> >>>> that I have error messages in Basex telling me theat access was >> >>>> refused. >> >>>> >> >>>> >> >>>> Yoann Maingon >> >>>> CEO - mydatalinx >> >>>> +33664324966 >> >> >> >> -- >> >> Dirk Kirsten, BaseX GmbH, http://basex.org >> >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >> >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >> >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >> >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >> >> >> > >> >> -- >> Dirk Kirsten, BaseX GmbH, http://basex.org >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > >
AB
Andy Bunce7 May 2014 12:44 #
Quoted text · Christian Grün · 1 line
>although I was surprised about the reported execution times at that time
Yes my test was a bit harsh :-)
ab -n 100 -c 10 http://localhost:8984/bsp/simple
Is 100 requests as fast as possible with 10 concurrent. I also had nearly 2Mb of parser code in XQuery generated by REX [1] just in one app.
Thanks for the tips.
/Andy
[1] http://www.bottlecaps.de/rex/
Quoted text · Christian Grün · 300 lines
On 7 May 2014 11:24, Christian Grün <christian.gruen at gmail.com> wrote: > > However one thing to be aware of with the current implementation is that > > response times depend on the quantity of XQuery code defined, making > large > > applications problematic. This was mentioned in Christian's recent > "Upcoming > > features" email, so I am sure it will be addressed soon. > > I agree with Andy (although I was surprised about the reported > execution times at that time). In one of our projects, we now have > around 500 KB of XQuery code, and the constant overhead for evaluating > a single REST request is about 40 ms - which may be too slow if you > have lots of requests per seconds. > > However, if you encounter bottlenecks, there are already various ways > to improve performance (all of them undocumented, I guess - once > again, Wiki edits are welcome..): > > * Move all XQuery modules without RESTXQ annotations into your > repository ("repo" directory) [1]. This can be done manually (there is > no need to use the REPO commands), and you can edit XQuery modules > directly in your repo directory. > > * Only keep those XQuery modules in your restxq directory which are > required in your project. > > The reason is that the restxq directory is scanned for changes every > time a new request takes place. We think about introducing a RELEASE > mode in a future version, in which various checks will be skipped that > are required during the development stage. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Repository > > > > > >> Hello Yoann, > >> > >> You do not "need to do so", but I remember your project quite well and I > >> was one of the people who said you don't actually need PHP. From what I > >> saw and remember, I think RestXQ is simply a much better fit. > >> > >> RestXQ enables you to do complete server-side processing (just like PHP > >> does) using XQuery. You can define all sorts of options for your > >> functions using annotations and how it should be served to your users. > >> > >> Theoretically, this would also be possible using Rest. However, the Rest > >> interface is more intended for short queries and querying on a data set. > >> You will always have to submit your query and of course this is very > >> impractical and slow if you develop a whole web app. > >> But it might be a good idea to add something to the documentation to > >> make the distinction between rest and RestXQ clearer. So much we could > >> add to the docs, actually... :) > >> > >> Cheers, > >> Dirk > >> > >> On 07/05/14 10:44, Yoann Maingon wrote: > >> > Thx > >> > > >> > I look into the provided example. At first I was more going into Rest > >> > and > >> > not RestXq, but if I need to do so then I guess I need to spend some > >> > time > >> > on it. > >> > Open sourcing our projects is a good question. > >> > I still have some colleagues affraid to somehow loose what they've > >> > developped and I don't have a clear opinion about it. But I'd be happy > >> > to > >> > share code (you may regret it! I'm a bad developper !) > >> > > >> > > >> > *Cordialement / Best Regards,* > >> > > >> > *Yoann Maingon* > >> > Minerva France > >> > > >> > *+33 6 64 32 49 66* > >> > > >> > Download Aras Innovator - Téléchargez Aras > >> > Innovator< > http://www.aras.com/support/downloads/downloadInnovator.aspx> > >> > > >> > > >> > > >> > > >> > 2014-05-07 10:18 GMT+02:00 Dirk Kirsten <dk at basex.org>: > >> > > >> >> Hi, > >> >> > >> >> I agree with Max that it would be a good idea to have a list of > >> >> projects > >> >> and examples, which are build on top of BaseX. A problem might be > that > >> >> many applications which are build on top of BaseX are not open > source. > >> >> > >> >> @Yoann: Please be aware that there is a Rest and RestXQ > implementation > >> >> within BaseX, which are quite different. What you most likely want to > >> >> use is RestXQ. Some documentation is available at > >> >> https://docs.basex.org/wiki/RESTXQ > >> >> Using RestXQ itself, there is an example for a blog at > >> >> https://github.com/siserle/blog-example > >> >> > >> >> As Max already suggested, the main difference when you use it with > >> >> angular or some other framework is that you most likely want to > return > >> >> JSON, so you have to change the output method. > >> >> > >> >> Cheers, > >> >> Dirk > >> >> > >> >> On 07/05/14 09:34, Maximilian Gärber wrote: > >> >>> Hi Yoann, > >> >>> > >> >>> I guess having examples like these would be helpful in general. > >> >>> Together with basex, we built a larger project for managing > conference > >> >>> registrations etc. last year. I could extract some of the modules - > >> >>> maybe we could manage to publish them on some github repo or a > >> >>> dedicated site? @basex: maybe it is time for a basex contrib page? > >> >>> > >> >>> What you need, is some json endpoint which leverages the session > >> >>> module, checks the credentials and returns some json back to Angular > >> >>> (or JQuey) > >> >>> > >> >>> Besides that, you need to secure all your restxq endpoints with a > >> >>> authentication check: > >> >>> > >> >>> if(not(session:logged-in())) then web:redirect($C:START-PAGE) > else > >> >>> _:do-something-useful() > >> >>> > >> >>> > >> >>> Login example: > >> >>> > >> >>> > >> >>> import module namespace session = > >> >>> "http://basex.org/modules/web/session > >> >> "; > >> >>> > >> >>> declare > >> >>> %restxq:path("/api/login/check") > >> >>> %restxq:POST("{$content}") > >> >>> %output:method("json") > >> >>> %output:json("lax=yes") > >> >>> function _:check( > >> >>> $content as item()* > >> >>> ) > >> >>> { > >> >>> let $user := $content//u/string() > >> >>> let $pass := $content//p/string() > >> >>> > >> >>> let $ok := _:check-user($user, $pass) > >> >>> > >> >>> if ($ok) then > >> >>> let $user-id := session:id() > >> >>> let $role := session:role() > >> >>> return((), > >> >>> <json objects="json"> > >> >>> <url>{_:redirect-url-from-role($role)}</url> > >> >>> </json> > >> >>> ) > >> >>> else > >> >>> <json objects="json"> > >> >>> <error>Login failed.</error> > >> >>> </json> > >> >>> }; > >> >>> > >> >>> > >> >>> angular.module('login', []) > >> >>> .config([ > >> >>> '$routeProvider', > >> >>> function ($routeProvider) { > >> >>> $routeProvider.when('/Logout', { > >> >>> redirectTo: '/restxq/logout' > >> >>> }); > >> >>> }]) > >> >>> > >> >>> .controller('LoginCtrl', [ > >> >>> '$scope', '$http', '$location', > >> >>> function ($scope, $http, $location) { > >> >>> $scope.login = function() { > >> >>> var url = '/restxq/api/login/check'; > >> >>> > >> >>> //use jquery here, because angular does not detect auto-fill > >> >>> data > >> >>> var payload = { > >> >>> u: $('#u').val(), > >> >>> p: $('#p').val() > >> >>> }; > >> >>> > >> >>> $http.post(url, payload). > >> >>> success(function(data) { > >> >>> if (data.error) { > >> >>> // trigger error status > >> >>> $scope.loginForm.$error.failed = true; > >> >>> } else { > >> >>> // redirect > >> >>> window.location.pathname = data.url; > >> >>> } > >> >>> }). > >> >>> error(function(data, status, headers, config) { > >> >>> alert("Could not load data from server.") > >> >>> }); > >> >>> }; > >> >>> }]); > >> >>> > >> >>> <div class="row" ng-controller="LoginCtrl"> > >> >>> <div class="span6 offset3"> > >> >>> <h2 class="alumni-name">Please Login</h2> > >> >>> > >> >>> <div class="alert alert-error" > >> >>> ng-show="loginForm.$error.failed"> > >> >>> <p> > >> >>> Incorrect login data. Please try again. > >> >>> </p> > >> >>> </div> > >> >>> <form name="loginForm"> > >> >>> <table cellpadding="3"> > >> >>> <tr> > >> >>> <td>Username  </td> > >> >>> <td><input type="text" name="u" id="u" ng-model="user" > >> >>> style="width:146px !important;margin:0"/></td> > >> >>> </tr> > >> >>> <tr> > >> >>> <td>Password   </td> > >> >>> <td><input id="p" name="p" ng-model="password" > >> >>> style="width:146px !important;margin:0" type="password" /></td> > >> >>> </tr> > >> >>> <tr> > >> >>> <td/> > >> >>> <td><button ng-click="login()" class="btn" > >> >>> style="width:152px !important;margin:0">Login</button> > >> >>> </td> > >> >>> </tr> > >> >>> </table> > >> >>> > >> >>> </form> > >> >>> </div> > >> >>> </div> > >> >>> > >> >>> Regards, > >> >>> > >> >>> Max > >> >>> > >> >>> > >> >>> > >> >>> > >> >>> 2014-05-07 1:38 GMT+02:00 Yoann Maingon > >> >>> <yoann.maingon at mydatalinx.com>: > >> >>>> Hi, > >> >>>> > >> >>>> After xmlprague and my presentation at the BaseX user group I was > >> >>>> told > >> >> (and > >> >>>> I agree) that it wasn't really smart to use php for what I was > >> >>>> building > >> >> as > >> >>>> it had almost no added value as I could directly query basex using > >> >>>> the > >> >> Rest > >> >>>> Interface. > >> >>>> > >> >>>> Does anyone as some example using either angularjs or jquery ? I > >> >>>> think > >> >> I'm > >> >>>> struggling with the login. Even just trying with a Rest test tool, > I > >> >> can see > >> >>>> that I have error messages in Basex telling me theat access was > >> >>>> refused. > >> >>>> > >> >>>> > >> >>>> Yoann Maingon > >> >>>> CEO - mydatalinx > >> >>>> +33664324966 > >> >> > >> >> -- > >> >> Dirk Kirsten, BaseX GmbH, http://basex.org > >> >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > >> >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > >> >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > >> >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > >> >> > >> > > >> > >> -- > >> Dirk Kirsten, BaseX GmbH, http://basex.org > >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > > > > >
AH
Quoted text · Maximilian Gärber · 2 lines
On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: > @basex: maybe it is time for a basex contrib page?
Nice idea!
We have just created
https://github.com/BaseXdb/basex-contrib
A github repository for
BaseX User Community Contributions
Quoted text · Yoann Maingon · 2 lines
On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> wrote: > Does anyone as some example using either angularjs or jquery ?
We just added a first project
BaseX-Web-NG
A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example
motivated by your initial question (screenshot [1]):
Looking forward to your examples and contributions!
Micheee and Holu
[1] https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png
YM
Yoann Maingon14 May 2014 11:53 #
Hi,
I've got two questions about using Basex with Angular, because I still have an issue accessing the XQuery module file.
Quick feasibility question for development: If I just install basex and store my angularjs app in the webapp folder will this is be ok to interact with the database?
The github repo shows a typical folder structure :
https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng What would it be if directly integrated in the basex folder? Might be a noob question, but I'm a bit struggling here. I'm looking for an easy to way to setup a dev environnement. I'm not too much about perf/dbsize for now.
Thx for your help.
*Cordialement / Best Regards,*
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>:
Quoted text · Maximilian Gärber · 33 lines
> On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: > > @basex: maybe it is time for a basex contrib page? > > Nice idea! > > We have just created > > https://github.com/BaseXdb/basex-contrib > > A github repository for > > BaseX User Community Contributions > > > On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> > wrote: > > Does anyone as some example using either angularjs or jquery ? > > We just added a first project > > BaseX-Web-NG > A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example > > motivated by your initial question (screenshot [1]): > > > Looking forward to your examples and contributions! > Micheee and Holu > > [1] > https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png > >
AB
Andy Bunce14 May 2014 16:25 #
Hi Yoann,
I do it like this:
http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex
/Andy
Quoted text · Yoann Maingon · 70 lines
On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> wrote: > Hi, > > I've got two questions about using Basex with Angular, because I still > have an issue accessing the XQuery module file. > > Quick feasibility question for development: If I just install basex and > store my angularjs app in the webapp folder will this is be ok to interact > with the database? > The github repo shows a typical folder structure : > https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng > What would it be if directly integrated in the basex folder? > Might be a noob question, but I'm a bit struggling here. I'm looking for > an easy to way to setup a dev environnement. I'm not too much about > perf/dbsize for now. > > Thx for your help. > > > > > > *Cordialement / Best Regards,* > > *Yoann Maingon* > Minerva France > > *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>* > > Download Aras Innovator - Téléchargez Aras Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> > > > > > 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: > > On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: >> > @basex: maybe it is time for a basex contrib page? >> >> Nice idea! >> >> We have just created >> >> https://github.com/BaseXdb/basex-contrib >> >> A github repository for >> >> BaseX User Community Contributions >> >> >> On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> >> wrote: >> > Does anyone as some example using either angularjs or jquery ? >> >> We just added a first project >> >> BaseX-Web-NG >> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example >> >> motivated by your initial question (screenshot [1]): >> >> >> Looking forward to your examples and contributions! >> Micheee and Holu >> >> [1] >> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png >> >> >
YM
Yoann Maingon14 May 2014 20:59 #
Thx for the blog post !
I was close to make it work but now I've got an issue with Basex itself. It says can't communicate with server when I'm trying to launch the basexhttp
I know it happened to me once on another computer never knew how I either fixed it or if I had my computer stolen since then.
Is there any log I should check, any cleaning advice?
*Cordialement / Best Regards,*
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-14 16:25 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>:
Quoted text · Andy Bunce · 81 lines
> Hi Yoann, > > I do it like this: > http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex > > /Andy > > > > On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> wrote: > >> Hi, >> >> I've got two questions about using Basex with Angular, because I still >> have an issue accessing the XQuery module file. >> >> Quick feasibility question for development: If I just install basex and >> store my angularjs app in the webapp folder will this is be ok to interact >> with the database? >> The github repo shows a typical folder structure : >> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng >> What would it be if directly integrated in the basex folder? >> Might be a noob question, but I'm a bit struggling here. I'm looking for >> an easy to way to setup a dev environnement. I'm not too much about >> perf/dbsize for now. >> >> Thx for your help. >> >> >> >> >> >> *Cordialement / Best Regards,* >> >> *Yoann Maingon* >> Minerva France >> >> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>* >> >> Download Aras Innovator - Téléchargez Aras Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> >> >> >> >> >> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: >> >> On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: >>> > @basex: maybe it is time for a basex contrib page? >>> >>> Nice idea! >>> >>> We have just created >>> >>> https://github.com/BaseXdb/basex-contrib >>> >>> A github repository for >>> >>> BaseX User Community Contributions >>> >>> >>> On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> >>> wrote: >>> > Does anyone as some example using either angularjs or jquery ? >>> >>> We just added a first project >>> >>> BaseX-Web-NG >>> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example >>> >>> motivated by your initial question (screenshot [1]): >>> >>> >>> Looking forward to your examples and contributions! >>> Micheee and Holu >>> >>> [1] >>> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png >>> >>> >> >
YM
Yoann Maingon15 May 2014 01:17 #
Working on this development including Basex and AngularJs, I'm stuck with the Json output.
here is the error :
[BXJS0002] JSON serializer: <objectType> has invalid attribute "label".
Here is the xqm :
module namespace _ = 'getObjectTypes';
(:~
: test dev YMA
:)
declare
%rest:path("/getObjectTypes")
(: %rest:query-param("name", "{$name}", "anonymous friend") :) %output:method("json")
%output:json("lax=yes")
function _:getObjectTypes() {
let $db := db:open("simplePLM_test1")//objectType
return <json objects="json">{$db}</json>
};
If instead I export in XML I get this :
<resultat>
<objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
label="nodes" name="nodes"/>
<objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
label="links" name="links"/>
</resultat>using this xqm:
module namespace _ = 'getObjectTypes';
(:~
: test dev YMA
:)
declare
%rest:path("/getObjectTypes")
(: %rest:query-param("name", "{$name}", "anonymous friend") :) %output:method("xml")
function _:getObjectTypes() {
let $db := db:open("simplePLM_test1")//objectType
return <resultat>{$db}</resultat>
};any idea?
*Cordialement / Best Regards,*
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-14 20:59 GMT+02:00 Yoann Maingon <yoann.maingon at minerva-plm.fr>:
Quoted text · Yoann Maingon · 107 lines
> Thx for the blog post ! > > I was close to make it work but now I've got an issue with Basex itself. > It says can't communicate with server when I'm trying to launch the > basexhttp > I know it happened to me once on another computer never knew how I either > fixed it or if I had my computer stolen since then. > > Is there any log I should check, any cleaning advice? > > > *Cordialement / Best Regards,* > > *Yoann Maingon* > Minerva France > > *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>* > > Download Aras Innovator - Téléchargez Aras Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> > > > > > 2014-05-14 16:25 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>: > > Hi Yoann, >> >> I do it like this: >> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex >> >> /Andy >> >> >> >> On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> wrote: >> >>> Hi, >>> >>> I've got two questions about using Basex with Angular, because I still >>> have an issue accessing the XQuery module file. >>> >>> Quick feasibility question for development: If I just install basex and >>> store my angularjs app in the webapp folder will this is be ok to interact >>> with the database? >>> The github repo shows a typical folder structure : >>> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng >>> What would it be if directly integrated in the basex folder? >>> Might be a noob question, but I'm a bit struggling here. I'm looking for >>> an easy to way to setup a dev environnement. I'm not too much about >>> perf/dbsize for now. >>> >>> Thx for your help. >>> >>> >>> >>> >>> >>> *Cordialement / Best Regards,* >>> >>> *Yoann Maingon* >>> Minerva France >>> >>> *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>* >>> >>> Download Aras Innovator - Téléchargez Aras Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> >>> >>> >>> >>> >>> 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: >>> >>> On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: >>>> > @basex: maybe it is time for a basex contrib page? >>>> >>>> Nice idea! >>>> >>>> We have just created >>>> >>>> https://github.com/BaseXdb/basex-contrib >>>> >>>> A github repository for >>>> >>>> BaseX User Community Contributions >>>> >>>> >>>> On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> >>>> wrote: >>>> > Does anyone as some example using either angularjs or jquery ? >>>> >>>> We just added a first project >>>> >>>> BaseX-Web-NG >>>> A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example >>>> >>>> motivated by your initial question (screenshot [1]): >>>> >>>> >>>> Looking forward to your examples and contributions! >>>> Micheee and Holu >>>> >>>> [1] >>>> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png >>>> >>>> >>> >> >
AG
Arve Gengelbach15 May 2014 09:07 #
Bonjour Yoann,
The mapping XML –> JSON is not 1-1, i.e. not any XML can be immediately serialised to JSON. Your XML has to be in a certain format (direct, attributes, jsonml or map) as described in [JSON Module].
I suggest you to template the JSON output you expect and apply
json:parse() with desired options. This is the same as specifying output options in RestXQ. By then you know which format your XML has to have. I.e. start like this...json:parse(
'{"resultat":[
{"objectType":[
{"label":"nodes",
"name":"nodes"}
]},
{"objectType":[
{"label":"links",
"name":"links"}
]}
]}', {"format":"direct"})hope this helps
Arve
[JSON Module] http://docs.basex.org/wiki/JSON_Module
Quoted text · Yoann Maingon · 160 lines
On 15 May 2014, at 01:17, Yoann Maingon <yoann.maingon at minerva-plm.fr> wrote: > Working on this development including Basex and AngularJs, I'm stuck with the Json output. > here is the error : > [BXJS0002] JSON serializer: <objectType> has invalid attribute "label". > Here is the xqm : > module namespace _ = 'getObjectTypes'; > > (:~ > : test dev YMA > :) > declare > %rest:path("/getObjectTypes") > (: %rest:query-param("name", "{$name}", "anonymous friend") :) > %output:method("json") > %output:json("lax=yes") > function _:getObjectTypes() { > let $db := db:open("simplePLM_test1")//objectType > return <json objects="json">{$db}</json> > }; > > If instead I export in XML I get this : > <resultat> > > > > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" label="nodes" name="nodes"/> > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" label="links" name="links"/> > </resultat> > > using this xqm: > > module namespace _ = 'getObjectTypes'; > > (:~ > : test dev YMA > :) > declare > %rest:path("/getObjectTypes") > (: %rest:query-param("name", "{$name}", "anonymous friend") :) > %output:method("xml") > function _:getObjectTypes() { > let $db := db:open("simplePLM_test1")//objectType > return <resultat>{$db}</resultat> > }; > > any idea? > > > > Cordialement / Best Regards, > > Yoann Maingon > Minerva France > > +33 6 64 32 49 66 > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > 2014-05-14 20:59 GMT+02:00 Yoann Maingon <yoann.maingon at minerva-plm.fr>: > Thx for the blog post ! > > I was close to make it work but now I've got an issue with Basex itself. > It says can't communicate with server when I'm trying to launch the basexhttp > I know it happened to me once on another computer never knew how I either fixed it or if I had my computer stolen since then. > > Is there any log I should check, any cleaning advice? > > > Cordialement / Best Regards, > > Yoann Maingon > Minerva France > > +33 6 64 32 49 66 > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > 2014-05-14 16:25 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>: > > Hi Yoann, > > I do it like this: http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex > > /Andy > > > > On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> wrote: > Hi, > > I've got two questions about using Basex with Angular, because I still have an issue accessing the XQuery module file. > > Quick feasibility question for development: If I just install basex and store my angularjs app in the webapp folder will this is be ok to interact with the database? > The github repo shows a typical folder structure : https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng > What would it be if directly integrated in the basex folder? > Might be a noob question, but I'm a bit struggling here. I'm looking for an easy to way to setup a dev environnement. I'm not too much about perf/dbsize for now. > > Thx for your help. > > > > > > Cordialement / Best Regards, > > Yoann Maingon > Minerva France > > +33 6 64 32 49 66 > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: > > On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: > > @basex: maybe it is time for a basex contrib page? > > Nice idea! > > We have just created > > https://github.com/BaseXdb/basex-contrib > > A github repository for > > BaseX User Community Contributions > > > On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> wrote: > > Does anyone as some example using either angularjs or jquery ? > > We just added a first project > > BaseX-Web-NG > A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example > > motivated by your initial question (screenshot [1]): > > > Looking forward to your examples and contributions! > Micheee and Holu > > [1] https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png > > > > >
YM
Yoann Maingon15 May 2014 09:57 #
Thx, I thought using option format=attribute would work but apparently not. So no I fixed my issue using building the json:
module namespace _ = 'getObjectTypes';
(:~
: test dev YMA
:)
declare
%rest:path("/getObjectTypes")
(: %rest:query-param("name", "{$name}", "anonymous friend") :)
%output:method("json")
function _:getObjectTypes() {
let $db := db:open("simplePLM_test1")//objectType
return <json type="object">
{
for $n in $db
return
<objectType type="object">
<name>{data($n/@name)}</name>
<label>{data($n/@label)}</label>
</objectType>
} </json>
};Thank you for your help !
*Cordialement / Best Regards,*
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-15 9:07 GMT+02:00 Arve Gengelbach <ag at basex.org>:
Quoted text · Arve Gengelbach · 208 lines
> Bonjour Yoann, > > The mapping XML –> JSON is not 1-1, i.e. not any XML can be immediately > serialised to JSON. Your XML has to be in a certain format (direct, > attributes, jsonml or map) as described in [JSON Module]. > > I suggest you to template the JSON output you expect and apply > json:parse() with desired options. This is the same as specifying output > options in RestXQ. By then you know which format your XML has to have. I.e. > start like this... > > json:parse( > '{"resultat":[ > {"objectType":[ > {"label":"nodes", > "name":"nodes"} > ]}, > {"objectType":[ > {"label":"links", > "name":"links"} > ]} > ]}', {"format":"direct"}) > > > hope this helps > Arve > > [JSON Module] http://docs.basex.org/wiki/JSON_Module > > On 15 May 2014, at 01:17, Yoann Maingon <yoann.maingon at minerva-plm.fr> > wrote: > > > Working on this development including Basex and AngularJs, I'm stuck > with the Json output. > > here is the error : > > [BXJS0002] JSON serializer: <objectType> has invalid attribute "label". > > Here is the xqm : > > module namespace _ = 'getObjectTypes'; > > > > (:~ > > : test dev YMA > > :) > > declare > > %rest:path("/getObjectTypes") > > (: %rest:query-param("name", "{$name}", "anonymous friend") :) > > %output:method("json") > > %output:json("lax=yes") > > function _:getObjectTypes() { > > let $db := db:open("simplePLM_test1")//objectType > > return <json objects="json">{$db}</json> > > }; > > > > If instead I export in XML I get this : > > <resultat> > > > > > > > > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > label="nodes" name="nodes"/> > > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > label="links" name="links"/> > > </resultat> > > > > using this xqm: > > > > module namespace _ = 'getObjectTypes'; > > > > (:~ > > : test dev YMA > > :) > > declare > > %rest:path("/getObjectTypes") > > (: %rest:query-param("name", "{$name}", "anonymous friend") :) > > %output:method("xml") > > function _:getObjectTypes() { > > let $db := db:open("simplePLM_test1")//objectType > > return <resultat>{$db}</resultat> > > }; > > > > any idea? > > > > > > > > Cordialement / Best Regards, > > > > Yoann Maingon > > Minerva France > > > > +33 6 64 32 49 66 > > > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > > > > > > > 2014-05-14 20:59 GMT+02:00 Yoann Maingon <yoann.maingon at minerva-plm.fr>: > > Thx for the blog post ! > > > > I was close to make it work but now I've got an issue with Basex itself. > > It says can't communicate with server when I'm trying to launch the > basexhttp > > I know it happened to me once on another computer never knew how I > either fixed it or if I had my computer stolen since then. > > > > Is there any log I should check, any cleaning advice? > > > > > > Cordialement / Best Regards, > > > > Yoann Maingon > > Minerva France > > > > +33 6 64 32 49 66 > > > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > > > > > > > 2014-05-14 16:25 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>: > > > > Hi Yoann, > > > > I do it like this: > http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex > > > > /Andy > > > > > > > > On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> > wrote: > > Hi, > > > > I've got two questions about using Basex with Angular, because I still > have an issue accessing the XQuery module file. > > > > Quick feasibility question for development: If I just install basex and > store my angularjs app in the webapp folder will this is be ok to interact > with the database? > > The github repo shows a typical folder structure : > https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng > > What would it be if directly integrated in the basex folder? > > Might be a noob question, but I'm a bit struggling here. I'm looking for > an easy to way to setup a dev environnement. I'm not too much about > perf/dbsize for now. > > > > Thx for your help. > > > > > > > > > > > > Cordialement / Best Regards, > > > > Yoann Maingon > > Minerva France > > > > +33 6 64 32 49 66 > > > > Download Aras Innovator - Téléchargez Aras Innovator > > > > > > > > > > > > 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: > > > > On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: > > > @basex: maybe it is time for a basex contrib page? > > > > Nice idea! > > > > We have just created > > > > https://github.com/BaseXdb/basex-contrib > > > > A github repository for > > > > BaseX User Community Contributions > > > > > > On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> > wrote: > > > Does anyone as some example using either angularjs or jquery ? > > > > We just added a first project > > > > BaseX-Web-NG > > A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example > > > > motivated by your initial question (screenshot [1]): > > > > > > Looking forward to your examples and contributions! > > Micheee and Holu > > > > [1] > https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png > > > > > > > > > > > >
YM
Yoann Maingon15 May 2014 18:22 #
In fact the Json I was building was not valid.
Now I understood how to fix it. Seems to work well :
module namespace _ = 'getObjectTypes';
(:~
: test dev YMA
:)
declare
%rest:path("/getObjectTypes")
(: %rest:query-param("name", "{$name}", "anonymous friend") :)
%output:method("json")
%output:json("format=attributes")
%output:json("lax=yes")
function _:getObjectTypes() {
let $db := db:open("simplePLM_test1")//objectType
return
<json type="array"> {
for $n in $db
return
<_ type="object">
<name type="string">
{data($n/@name)}
</name>
<label type="string">
{data($n/@label)}
</label>
</_>
} </json>
};Question now will be how you ouput nested structure with unknown depth. Any idea or Experience ?
*Cordialement / Best Regards, *
*Yoann Maingon*
Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras
Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx>
2014-05-15 9:57 GMT+02:00 Yoann Maingon <yoann.maingon at minerva-plm.fr>:
Quoted text · Yoann Maingon · 253 lines
> Thx, I thought using option format=attribute would work but apparently > not. > So no I fixed my issue using building the json: > > module namespace _ = 'getObjectTypes'; > > (:~ > : test dev YMA > :) > declare > %rest:path("/getObjectTypes") > (: %rest:query-param("name", "{$name}", "anonymous friend") :) > %output:method("json") > function _:getObjectTypes() { > let $db := db:open("simplePLM_test1")//objectType > return <json type="object"> > { > for $n in $db > return > <objectType type="object"> > <name>{data($n/@name)}</name> > <label>{data($n/@label)}</label> > </objectType> > } </json> > }; > > Thank you for your help ! > > > *Cordialement / Best Regards,* > > *Yoann Maingon* > Minerva France > > *+33 6 64 32 49 66 <%2B33%206%C2%A064%2032%2049%2066>* > > Download Aras Innovator - Téléchargez Aras Innovator<http://www.aras.com/support/downloads/downloadInnovator.aspx> > > > > > 2014-05-15 9:07 GMT+02:00 Arve Gengelbach <ag at basex.org>: > >> Bonjour Yoann, >> >> The mapping XML –> JSON is not 1-1, i.e. not any XML can be immediately >> serialised to JSON. Your XML has to be in a certain format (direct, >> attributes, jsonml or map) as described in [JSON Module]. >> >> I suggest you to template the JSON output you expect and apply >> json:parse() with desired options. This is the same as specifying output >> options in RestXQ. By then you know which format your XML has to have. I.e. >> start like this... >> >> json:parse( >> '{"resultat":[ >> {"objectType":[ >> {"label":"nodes", >> "name":"nodes"} >> ]}, >> {"objectType":[ >> {"label":"links", >> "name":"links"} >> ]} >> ]}', {"format":"direct"}) >> >> >> hope this helps >> Arve >> >> [JSON Module] http://docs.basex.org/wiki/JSON_Module >> >> On 15 May 2014, at 01:17, Yoann Maingon <yoann.maingon at minerva-plm.fr> >> wrote: >> >> > Working on this development including Basex and AngularJs, I'm stuck >> with the Json output. >> > here is the error : >> > [BXJS0002] JSON serializer: <objectType> has invalid attribute "label". >> > Here is the xqm : >> > module namespace _ = 'getObjectTypes'; >> > >> > (:~ >> > : test dev YMA >> > :) >> > declare >> > %rest:path("/getObjectTypes") >> > (: %rest:query-param("name", "{$name}", "anonymous friend") :) >> > %output:method("json") >> > %output:json("lax=yes") >> > function _:getObjectTypes() { >> > let $db := db:open("simplePLM_test1")//objectType >> > return <json objects="json">{$db}</json> >> > }; >> > >> > If instead I export in XML I get this : >> > <resultat> >> > >> > >> > >> > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >> label="nodes" name="nodes"/> >> > <objectType xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >> label="links" name="links"/> >> > </resultat> >> > >> > using this xqm: >> > >> > module namespace _ = 'getObjectTypes'; >> > >> > (:~ >> > : test dev YMA >> > :) >> > declare >> > %rest:path("/getObjectTypes") >> > (: %rest:query-param("name", "{$name}", "anonymous friend") :) >> > %output:method("xml") >> > function _:getObjectTypes() { >> > let $db := db:open("simplePLM_test1")//objectType >> > return <resultat>{$db}</resultat> >> > }; >> > >> > any idea? >> > >> > >> > >> > Cordialement / Best Regards, >> > >> > Yoann Maingon >> > Minerva France >> > >> > +33 6 64 32 49 66 >> > >> > Download Aras Innovator - Téléchargez Aras Innovator >> > >> > >> > >> > >> > >> > 2014-05-14 20:59 GMT+02:00 Yoann Maingon <yoann.maingon at minerva-plm.fr >> >: >> > Thx for the blog post ! >> > >> > I was close to make it work but now I've got an issue with Basex itself. >> > It says can't communicate with server when I'm trying to launch the >> basexhttp >> > I know it happened to me once on another computer never knew how I >> either fixed it or if I had my computer stolen since then. >> > >> > Is there any log I should check, any cleaning advice? >> > >> > >> > Cordialement / Best Regards, >> > >> > Yoann Maingon >> > Minerva France >> > >> > +33 6 64 32 49 66 >> > >> > Download Aras Innovator - Téléchargez Aras Innovator >> > >> > >> > >> > >> > >> > 2014-05-14 16:25 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>: >> > >> > Hi Yoann, >> > >> > I do it like this: >> http://quodatum.wordpress.com/2014/05/14/using-angular-with-basex >> > >> > /Andy >> > >> > >> > >> > On 14 May 2014 10:53, Yoann Maingon <yoann.maingon at minerva-plm.fr> >> wrote: >> > Hi, >> > >> > I've got two questions about using Basex with Angular, because I still >> have an issue accessing the XQuery module file. >> > >> > Quick feasibility question for development: If I just install basex and >> store my angularjs app in the webapp folder will this is be ok to interact >> with the database? >> > The github repo shows a typical folder structure : >> https://github.com/BaseXdb/basex-contrib/tree/master/basex-web-ng >> > What would it be if directly integrated in the basex folder? >> > Might be a noob question, but I'm a bit struggling here. I'm looking >> for an easy to way to setup a dev environnement. I'm not too much about >> perf/dbsize for now. >> > >> > Thx for your help. >> > >> > >> > >> > >> > >> > Cordialement / Best Regards, >> > >> > Yoann Maingon >> > Minerva France >> > >> > +33 6 64 32 49 66 >> > >> > Download Aras Innovator - Téléchargez Aras Innovator >> > >> > >> > >> > >> > >> > 2014-05-07 15:21 GMT+02:00 Alexander Holupirek <alex at holupirek.de>: >> > >> > On 07.05.2014, at 09:34, Maximilian Gärber <mgaerber at arcor.de> wrote: >> > > @basex: maybe it is time for a basex contrib page? >> > >> > Nice idea! >> > >> > We have just created >> > >> > https://github.com/BaseXdb/basex-contrib >> > >> > A github repository for >> > >> > BaseX User Community Contributions >> > >> > >> > On 07.05.2014, at 01:38, Yoann Maingon <yoann.maingon at mydatalinx.com> >> wrote: >> > > Does anyone as some example using either angularjs or jquery ? >> > >> > We just added a first project >> > >> > BaseX-Web-NG >> > A BaseX-RestXQ-AngularJS-Bootstrap-WebApp example >> > >> > motivated by your initial question (screenshot [1]): >> > >> > >> > Looking forward to your examples and contributions! >> > Micheee and Holu >> > >> > [1] >> https://raw.githubusercontent.com/BaseXdb/basex-contrib/master/basex-web-ng/public/static/gfx/Hello_Stranger.png >> > >> > >> > >> > >> > >> >> >
Written for BaseX 7.8. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery