Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement eXistdb REST-api client #243

Merged
merged 13 commits into from
Aug 8, 2022
Merged

Conversation

line-o
Copy link
Member

@line-o line-o commented Jul 19, 2022

node-exist exports a new async function getRestClient accepting the
same connection options as connect did.
The returned client has three methods get, post, put and del to
interact with eXist-db using the REST-API

const { getRestClient } = require('../../index')
const rc = await getRestClient(connectionOptions)
await rc.put('<root />', '/db/test.xml')
await rc.get('/db/test.xml')
await rc.post('/db', query, options)
await rc.del('/db/test.xml')

see example/rest.mjs for a runnable version of above code

Copy link
Contributor

@duncdrum duncdrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall the api design looks good to me. Very nice feature. Geting collection listing in JSON might be useful, but its something i would add once we have a usecase that isn't served by xst. Posting xquerys on the other hand is something that I personally would have use for, it would be nice to add that.

The Roadmap on the Readme should be updated with this PR, and it needs some documentation / sample code.

I would add another test on specs/rest.js to ensure that exist reports the correct mimetypes for uploaded txt and xml files. This is an area of frequent problems.

@line-o line-o changed the title Create, read and remove resources using the REST-api implement eXistdb REST-api client Aug 5, 2022
@line-o
Copy link
Member Author

line-o commented Aug 5, 2022

@duncdrum added POST, more tests, documentation and the feature server responses that are wrapped in <exist:result> will now extend the returned response with some useful metadata extracted (start, hits, count, ....)

@line-o line-o mentioned this pull request Aug 5, 2022
@line-o line-o requested a review from duncdrum August 6, 2022 21:37
@duncdrum
Copy link
Contributor

duncdrum commented Aug 8, 2022

@line-o feel free to merge after rebasing, the rebase and merge button is greyed out for me, so i guess you need to resolve some conflict first

node-exist exports a new async function `getRestClient` accepting the
same connection options as connect did.
The returned client has three methods `get`, `put` and `del` to
read, create and remove resources from exist using the REST API.

```
const rc = await getRestClient(connectionOptions)
await rc.put('<root />', '/db/test.xml')
await rc.get('/db/test.xml')
await rc.del('/db/test.xml')
```
Using the REST-client is around 20% faster in uploading files.
In order to receive detailed validation errors it falls back to
using the RPC-API on files where the server responded with status code
400, bad request.
The ability to require 'util/types' was introduced only with node15.
This enables easier import of connection.js in ES6 modules.
whenever a wrapped result is returned from a request
to eXist-db's REST-API (for both GET and POST) the
response will be extended with metadata derived
from the <exist:result> elements attributes.

- hits
- start
- count
- session
- compilationTime
- executionTime

If any of the above attributes is not set the property is set
to -1.
@line-o line-o merged commit 911a164 into eXist-db:main Aug 8, 2022
@line-o line-o deleted the feat/rest-resources branch August 8, 2022 08:33
@github-actions
Copy link

github-actions bot commented Aug 8, 2022

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants