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

Feature issue #53 rest db #58

Merged
merged 9 commits into from
Feb 27, 2022
Merged

Feature issue #53 rest db #58

merged 9 commits into from
Feb 27, 2022

Conversation

grantmacken
Copy link
Contributor

@grantmacken grantmacken commented Feb 12, 2022

issue #53
enables rest interaction with xqerl db collections and XDM items

Uses cowboy rest handler in conjunction with xQuery main modules,
to allow CRUD ops on xqerl database collections and items.

  • POST collection URI with request body and ''content-type' header and optional Slug creates a resource
  • GET collection URI with accept header retrieves lists collection resources
  • GET resource URI with accept header retrieves serialized XDM item
  • PUT resource URI with content-type header and request body updates resource
  • DELETE resource URI deletes resource
  • HEAD resource URI, with accept header determines resource available status and provide content-length header
  • HEAD collection URI, with accept header determine if collection available.and provide content-length header
  • OPTIONS collection URI, allowable methods for collection.

checks: Curl is used to to check correct responses to HTTP requests
https://github.com/grantmacken/xqerl/runs/5169676947?check_suite_focus=true

Content negotiation
GET and HEAD request can return different resource representations depending on Accept Header
example: retrieving a list of collection items

curl -s  -H  'Accept: application/xml' http://localhost:8081/db/example.com/docs
# Returns  list as XML (serialised XDM document-node  )
curl -s  -H  'Accept: application/json' http://localhost:8081/db/example.com/docs
# Returns list as json (serialized XDM array)
curl -s  -H  'Accept: text/plain' http://localhost:8081/db/example.com/docs
# Returns list as text

HEAD request can be used to check for db collection or resource item availability.
HEAD request provides content-length header so you can determine resource size

DELETE requests only are available for items not collections as
deleting collections looks a bit dangerous but I can try to enable if requested

POSTS when posting requests MUST use a content-type header
at the moment only XML or JSON data types are accepted.
If there is a SLUG header then that will be used as the item name
otherwise the item name is generated as a uuid

curl -s  \
--header  'content-type: application/xml'  \
--header 'Slug: my-doc.xml'  \
-d '<data>test</data>'
http://localhost:8081/db/example.com/docs

The POST 'content-type' XML or JSON limitation is not set in stone and can be extended later.
e.g. when posting CSV, this can be stored as XDM array item.
then you might want to retrieve the resource using an Accept Header as text, JSON array or XML

… endpoint

enables POST, GET, PUT, DELETE requests to create, retrieve, update and delete
xqerl database items. A GET on a DB collection will list database items. Checks
are added to via feat.yml

add swtch on type, any, item or collection
add rest db checks
get can retrieve resources or collections
feat: return collections as text,xml or json
ci:(check) can list as text or json
refactor: add get_uri func
ci: comment out rm collection section
change ext var to base
refactor: use func to make more readable
ci: rest api check unsupported media type
feat:only create if looks like a domain
ci: rest api checks
@grantmacken grantmacken mentioned this pull request Feb 12, 2022
@zadean zadean merged commit 26f95c6 into zadean:main Feb 27, 2022
@zadean
Copy link
Owner

zadean commented Feb 27, 2022

Very cool!! Thank you for this @grantmacken!

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

Successfully merging this pull request may close these issues.

2 participants