CLARIAH / grlc

grlc builds Web APIs using shared SPARQL queries
http://grlc.io
MIT License
137 stars 32 forks source link

Does grlc support POST body? #374

Closed rajaram5 closed 2 years ago

rajaram5 commented 2 years ago

Hi @c-martinez I wonder if grlc server supports POST methods with request body. I also like to extract the values from the POST body and use it in the query. Does grlc support this functionality?

c-martinez commented 2 years ago

Hi @rajaram5,

Yes it is possible! grlc already supports this functionality.

See https://github.com/CLARIAH/grlc#method for reference, but basically you need to include the #+ method: POST decorator, and then you can call your query via post like this:

curl -X POST "http://grlc.io/api-git/CLARIAH/grlc-queries/method?endpoint=https%3A%2F%2Fdbpedia.org%2Fsparql" -H "accept: text/csv"

Hope this helps?

rajaram5 commented 2 years ago

Yes, I understood method config but I want to pass request body as part of my API and use values from the request body in the SPARQL query. Is this possible with glrc?

c-martinez commented 2 years ago

Do you mean something like:

curl -X POST "http://grlc.io/api-git/CLARIAH/grlc-queries/method" -H "accept: text/csv" -d "endpoint=https://Fdbpedia.org/sparql"

that would work.

rajaram5 commented 2 years ago

No something like example below. I am want to pass data in my request body. In this case I am passing gender uri. I also want to use this gender uri in the SPARQL query

curl -X POST https://example.com/beacon2/api/individuals -d '{"gender": "http://purl.obolibrary.org/obo/NCIT_C20197"}'

c-martinez commented 2 years ago

I think that should work. I just tried:

curl -X POST "http://grlc.io/api-git/CLARIAH/grlc-queries/method" -d '{ "endpoint": "https://dbpedia.org/sparql" }'

and it worked.

Do let me know if it does not work for your use case

rajaram5 commented 2 years ago

Ok let me give it a try