Tuesday, June 19, 2012

RavenDB: accessing a specific database using the HTTP API

RavenDB offers the following options to access it:
  • .NET Client API: The Client API allows easy access to it from any .NET language. The .NET Client API exposes all aspects of the RavenDB server to your application in a seamless manner.
  • HTTP API: RavenDB provides an HTTP API for accessing and manipulating data on the server. This API sits next to the C# Client API, providing most of the same functionality, but with a platform agnostic, web friendly interface. Using the HTTP API, it's possible to write a fully functioning RavenDB application using just Javascript and HTML.
For a demo application I’m building I wanted to use the HTTP API but I only had one problem, what’s the correct URL to access data in a specific RavenDB database?
To access data(e.g. docs) in the default database, you can use:
curl -X GET http://localhost:8080/docs/locations/1

But I created a specific database instance, what’s the impact on the URL? After some trial and error I discovered that the syntax is the following:

curl -X GET http://localhost:8080/databases/{databaseName}/docs/{document_id}

No comments: