Replacing documents in remote database

Thursday, 2 June 2016 · 5 messages
A
Asxetos2 Jun 2016 16:09 #
Hey all, I am trying to connect to a remote database and replace its files. I am using db:replace() inside client:query(), but I don't get how I am supposed to pass $input as the new data for the file in the database. Here a quick code snippet I put together: http://sprunge.us/jdaZ ( or http://sprunge.us/OZHj?xquery ) If there's a better method for doing what I am trying, I'm fine with replacing my whole method, even if that is using some sort of REST API and http requests. Just give me some pointers ;) Thanks!
CG
Christian Grün2 Jun 2016 16:15 #
Hi Asxetos,
Quoted text · Asxetos · 3 lines
> Here a quick code snippet I put together: > http://sprunge.us/jdaZ > ( or http://sprunge.us/OZHj?xquery )
If you use db:replace, you should probably specify your document inside the query. However, the REST API may be more appropriate for your scenario. Did you already have a look at our documentation [1]? If you want to send your request via XQuery, you can use the HTTP Module [2]. Hope this helps, Christian [1] http://docs.basex.org/wiki/Developer_Section [2] http://docs.basex.org/wiki/HTTP_Module
Quoted text · Asxetos · 7 lines
> > If there's a better method for doing what I am > trying, I'm fine with replacing my whole method, > even if that is using some sort of REST API and > http requests. Just give me some pointers ;) > > Thanks!
A
Asxetosin reply to Asxetos, 2 Jun 2016, 16:092 Jun 2016 16:17 #
aha! it seems the REST API[0] does work! I guess I can do my db:replace() using HTTP PUT requests [0]: http://docs.basex.org/wiki/REST [1]: http://docs.basex.org/wiki/REST#PUT_Method
Quoted text · Asxetos · 19 lines
On 2 June 2016 at 17:09, Asxetos <pure.asxetos at gmail.com> wrote: > Hey all, > > I am trying to connect to a remote database > and replace its files. I am using db:replace() > inside client:query(), but I don't get how I am > supposed to pass $input as the new data for > the file in the database. > > Here a quick code snippet I put together: > http://sprunge.us/jdaZ > ( or http://sprunge.us/OZHj?xquery ) > > If there's a better method for doing what I am > trying, I'm fine with replacing my whole method, > even if that is using some sort of REST API and > http requests. Just give me some pointers ;) > > Thanks!
A
Asxetosin reply to Christian Grün, 2 Jun 2016, 16:152 Jun 2016 16:24 #
Quoted text · Christian Grün · 10 lines
On 2 June 2016 at 17:15, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Asxetos, > >> Here a quick code snippet I put together: >> http://sprunge.us/jdaZ >> ( or http://sprunge.us/OZHj?xquery ) > > If you use db:replace, you should probably specify your document > inside the query. >
yeah, my guess is that I'd have to serialize the document in some way because it exists on the local filesystem, but not on the remote. So, I am reading the document, but cannot just concat it in the query. It also feels wrong.
Quoted text · Christian Grün · 4 lines
> However, the REST API may be more appropriate for your scenario. Did > you already have a look at our documentation [1]? If you want to send > your request via XQuery, you can use the HTTP Module [2]. >
Yep, the REST API seems to be it. I've already tried it with Postman. And yes, I'll probably use the HTTP xq module. It'd be nice if there was a way trigger a backup with the REST API, but I guess it's not a big deal.
Quoted text · Christian Grün · 6 lines
> Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Developer_Section > [2] http://docs.basex.org/wiki/HTTP_Module >
bwt, that was a super fast response! Thanks!
CG
Christian Grün2 Jun 2016 16:28 #
Quoted text · Asxetos · 2 lines
> It'd be nice if there was a way trigger a backup with the REST API, > but I guess it's not a big deal.
The easiest way I guess is to use the GET method and the command operation: http://localhost:8984/rest?command=create+backup+name-of-your-database
Quoted text · Asxetos · 1 line
> bwt, that was a super fast response! Thanks!
You are welcome ;)

⚡Generated with XQuery