REST questions

Sunday, 31 October 2010 · 2 messages
NA
Nigel Alderton31 Oct 2010 17:32 #
I'm hoping to find a step-by-step 'hello world' example for using the BaseX REST interface. To clarify, I want to be able to: 1. Start the REST service. ========================== When I start the BaseX server by doing; C:\>java -cp basex-6.3.jar org.basex.BaseXServer -s does that also start the REST service? 2. Test the rest service. ========================= How can I test if the REST service is running on localhost? Pointing a browser at http://localhost:8984/basex/jax-rx/ returns the following error; error on line 1 at column 1: Document is empty If I 'View Source' for that page in the browser, the source is just; Connection refused: connect 3. Using REST. ============== How do I create a restful interface? Say I want to create a REST API that simply does the following;
	An HTTP GET to locahost:8984/basex/jax-rx/foo/ returns <hello/>
	An HTTP GET to locahost:8984/basex/jax-rx/bar/ returns <world/>
How do I build that interface? What are the steps? Are 'foo' and 'bar' collections? What's the overall structure? 4. Documentation ================ I know that formal documentation is a bit thin on the ground, but would anyone be willing to send me their own informal personal notes about BaseX REST? I am currently struggling to even get started with the BaseX REST API. Nigel
CG
Christian Grün31 Oct 2010 19:32 #
Hi Nigel, thanks for the detailed wish list. First of all, I'd advise to follow the steps described at http://basex.org/rest. This tutorial seems to be well accepted by our users. As you might have seen, it's still based on version 6.1, so it will be updated with the next official release.
Quoted text · Nigel Alderton · 8 lines
> 1. Start the REST service. > ========================== > > When I start the BaseX server by doing; > > C:\>java -cp basex-6.3.jar org.basex.BaseXServer -s > > does that also start the REST service?
No; the Jetty server and some other external libraries are needed to run the REST service; these aren't included in the default distribution of BaseX (which doesn't rely on any external packages), but found in the basex-api.zip package instead. We'll soon automatize the process of including a runnable REST/JaxRx version in each minor release.
Quoted text · Nigel Alderton · 5 lines
> 2. Test the rest service. > ========================= > > How can I test if the REST service is running on localhost? Pointing a > browser at http://localhost:8984/basex/jax-rx/ returns the following error;
If you follow the tutorial, you shouldn't encounter any problems; just tell us if you need an updated, precompiled version of the basex-api.zip distribution package. Note, next, that all browsers will give you different results. Some browsers will display the result as XML, whereas others (such as Chrome) doesn't show anything. You might try tools like 'curl' to get all output printed on screen.
Quoted text · Nigel Alderton · 1 line
> Connection refused: connect
This indicates that the web server hasn't been started; see 1.
Quoted text · Nigel Alderton · 7 lines
> 3. Using REST. > ============== > How do I create a restful interface? Say I want to create a REST API that > simply does the following; > > An HTTP GET to locahost:8984/basex/jax-rx/foo/ returns <hello/> > An HTTP GET to locahost:8984/basex/jax-rx/bar/ returns <world/>
Hm, I'm not sure what you want to do here. If your database "foo" includes the document "<hello/>", you'll indeed get this result. Note that the next version of REST/JaxRx, on which we're currently working, will support hierarchical paths; i.e., you'll be able to watch parts of a database by specifying the correspondent collection path. An example: locahost:8984/basex/jax-rx/YourDB/path/to/relevant/documents?query=query/to/be/executed Hope thie helps, Christian

⚡Generated with XQuery