API Design Notes Part 2

22 Feb 2014

API Layout

url verb   response code
http://localhost:1337/api  GET    Billboard  200
http://localhost:1337/api/movies  GET    LIST Movies  200
http://localhost:1337/api/movies/{id}   GET    Get Individual Movie  200
http://localhost:1337/api/movies/{id}   PUT    Update Existing Movie  200
http://localhost:1337/api/movies/{id}   DELETE    Delete Existing Movie  204
http://localhost:1337/api/movies POST    Create New Movie  201
http://localhost:1337/api/persons  GET    LIST Persons  200
http://localhost:1337/api/persons/{id}   GET    Get Individual Person  200
http://localhost:1337/api/persons/{id}   PUT    Update Existing Person  200
http://localhost:1337/api/persons/{id}   DELETE    Delete Existing Person  204
http://localhost:1337/api/persons POST    Create New Person  201
http://localhost:1337/api/m2p  GET    LIST MovieToPerson Relationships   200
http://localhost:1337/api/m2p/{id}   GET    Get Individual MovieToPerson Relationship  200
http://localhost:1337/api/m2p/{id}   PUT    Update Existing MovieToPerson Relationship  200
http://localhost:1337/api/m2p/{id}   DELETE    Delete Existing MovieToPerson Relationship  204
http://localhost:1337/api/m2p POST    Create New MovieToPerson Relationship  201

API Testing

GET Billboard

curl -v -X GET http://localhost:1337/api/ -H "Connection: close" -H "Cache-Control: no-cache"

GET Movie Collection

curl -v -X GET http://localhost:1337/api/movies -H "Connection: close" -H "Cache-Control: no-cache"

CREATE Movie Item

curl -v -X POST -d '{"template":{"data":[{"name":"text","value":"testing"},{"name":"junk","value":""}]}}' http://localhost:1337/api/movies -H "Content-Type: application/vnd.collection+json" -H "Connection: close" -H "Cache-Control: no-cache"

GET Movie Item

curl -v -X GET http://localhost:1337/api/movies/123 -H "Connection: close" -H "Cache-Control: no-cache"

UPDATE Movie Item

curl -v -X PUT -d '{"template":{"data":[{"name":"text","value":"testing"},{"name":"junk","value":""}]}}' http://localhost:1337/api/movies/123 -H "Content-Type: application/vnd.collection+json" -H "Connection: close" -H "Cache-Control: no-cache"

DELETE Movie Item

curl -v -X DELETE -d '{"template":{"data":[{"name":"text","value":"testing"},{"name":"junk","value":""}]}}' http://localhost:1337/api/movies/123 -H "Content-Type: application/vnd.collection+json" -H "Connection: close" -H "Cache-Control: no-cache"

Reference