Develop API : – URI resource should be plural – Lowercase letters should be preferred in URI paths. – Don’t use hyphen, it look terrible style. – Don’t try to put much resources in URI format like this : http://api.canvas.restapi.org/shapes/polygons/quadrilaterals/squares
Don’t couple your API with Data Model, It may not map 1:1 with Domain Object
May not return full tree with root level request
Get /customers/1 to return customer data
Get /customers/1/orders to return orders belong customer
Avoid deeply/hard URI structure : /customers/1/orders/123/items/1/products/2 , should separate it into new endpoint
Response of each URL :
Always check Model validation, Use Filter Or Middleware to validate to make separation of concerns
Using Proper HTTP Status Code : 200, 201, 204, 400, 401, 404, 500.
Avoid Null Exception , should return Not Found.
Avoid using domain objects / entities as your API model , can be add new DTO for each request POST/ PUT.
Apply HATEOAS : To enable navigation to related resources
Test API : – Unit test, Integration Test, Functional Tests (Automation Test) – Test API with Test Server, POSTMAN. – Integrate POSTMAN with pipeline : NEWMAN.
Versioning web API – URI Versioning : api.domain.com/v2/customers/1 – Query string Versioning : api.domain.com/customers/1?ver=2 – Header Versioning : api.domain.com/customers/1 Version-Header: 2