Skip to content

REST API Style Resource Example

bjbbarr edited this page Mar 21, 2013 · 14 revisions

The user resource describes an example user entity. A user resource looks like this when rendered as application/json:

{
  first: "Friedrich",
  last: "Strohmeyer",
  notes: "I discovered Cadmium.",
  address: "123 Cadmium Blvd"
}

Calling a GET method with the path "/example/users" will return a listing in json format of user objects.

GET /example/users
> Accepts: application/json
< 200
< Content-Type: application/json
[
  { first: "Friedrich", last: "Strohmeyer", id="12345" },
  { first: "example", last: "user", id="12987" },
  ...
]

Now that you have the "id" for a particular user object you can now pass it into a GET method to receive specific data for that user.

GET /example/users/{id}
> Accepts: application/json
< 200
< Content-Type: application/json
{
  first: "Friedrich",
  last: "Strohmeyer",
  notes: "I discovered Cadmium.", 
  address: "123 Cadmium Blvd"
}

You can also pass the "id" into a PUT method to update fields on the user object. Here the is an example of the user object getting updated.

PUT /example/users/{id}
> Content-Type: application/json
{
  first: "Friedrich",
  last: "Strohmeyer",
  notes: "Cadmium is cool.", 
  address: "123 S. Cadmium Blvd"
}
< 204

To remove a user object you would just pass the "id" for the user you want to remove, calling a DELETE method.

DELETE /example/users/{id}
< 204
Clone this wiki locally