понедельник, 25 ноября 2013 г.

Some about REST

Intro
Many peoples say about REST. And I want only save some keynotes for myself.
There are protocol for communacation beyond server and you client application.

Favorite methods:
POST - for create new resourse
DELETE - delete resourse
GET - for get resourse

Other information must contain in HTTP Headers. There are: format, encoding and something else.

For example:
curl -XDELETE http://localhost/api/v1.0/users/123

curl -XGET http://localhost/api/v1.0/users/

Next:
curl -H 'Accept: text/csv' http://localhost/api/v1.0/books -o books.csv
Get all books in csv format and safe for books.csv file.

Next:
curl -XPOST -H 'Content-type: application/json' -d '{"name":"Alex"}' \
  http://localhost/api/v1.0/users -D -
Create new user (content data in -d parameter) and print response to STDOUT.
-D - print to STDOUT

Next for example:
curl -XPOST -H 'Content-type: application/json' \
  -d '{"subject":"Good news, everyone!","body":"..."}' \
  http://localhost/api/v1.0/commands/notify_all_users_via_email

Thank for http://eax.me/rest/

Комментариев нет:

Отправить комментарий