This page contains very brief information on :
Rest
Here, I am giving short examples of common rest calls
GET sample signature:
/ books/{ISBN}
/books/{ISBN}/categories
/books?title=M&author=alice&offset=42&pagesize=20
Sample request :
GET /users
data response: [{userId:1, username: ”alice”, userStatus:”silver”}, {userId:2, username: ”jackson”, userStatus:”gold”}]
POST sample signature:
POST
/carts
/carts/{id}/books
POST /users request :{ username: “fresh”, userStatus: “gold”}
reply : { id: 101, username: “fresh”, userStatus: “gold”} — reply came with user id
PUT sample signature
PUT /users/{userId} request: {userStatus: “silver”} — sets given user status to silver
DELETE sample signature
/carts/{id}/books/{ISBN} –deletes the given book from cart
Taking action on a resource
How do you take action on a shopping cart, such as checkout?
Option 1
POST /carts/{ID}?action=checkout
Option 2
POST /purchases/carts/{cartId}
Option 3
POST /carts/{id}/purchases
Common Rest Codes
Rest return codes 200: OK, 201: Created, 204: NO Content, 304: NOT Modified, 400: Bad Request, 401: Not Authorized, 404: Not Found, 500: Internal Server Error
JSON data example
Objects: { “attribute1” : 123, “attribute2”:true, “attribute3”:{“A”:1,”B”:2} , “attribute 4”: [1,2,3,4], “attribute 5”:null}
–attribute1 is a numeric attribute
–attribute2 is a boolean attribute
– attribute3 is a map
–attribute4 is an array
–attribute5 is null
Rest vs RPC
Rest APIs are scalable. They are simple and standardized, making them easy to use. Rest is built over HTTP, which is well understood. Rest provides fast performance via its caching ability (client or edge).
However, the rest protocol has a heavy payload.
RPC has light payloads and high performance. RPC isn’t standardized and requires enterprise software, which may be expensive.
More detailed information on rest API can be found in the book: