This document discusses RESTful APIs and how to test them. It begins with an overview of RESTful APIs and how they map HTTP methods to CRUD operations. It then provides an example of implementing a RESTful API in Flask. The document concludes by describing methods for testing RESTful APIs, including using browser addons, cURL, writing custom test code with the requests module, and using a framework like unittest. Code examples are provided for testing a RESTful API using unittest.
4. Time passes on ...
HTTP Methods
GET : Read A Resource
POST : Create a Resource
PUT : Update a Resource
DELETE : Delete a Resource
Response
Status Code, Content
7. Test Your REST API
Write tests for successful failure!
GET http://example.com/todos/
It should successfully return 404 status code
DELETE http://example.com/todos/-1
It should successfully return 404 status code
Check the status code and also the error message!
8. Test Your REST API
Write tests for successful success!
GET http://example.com/todos/1
It should successfully return the to_do item with task id 1 and 200 status code
DELETE http://example.com/todos/1
It should successfully delete the task with id 1 return 204 status code
Check the status code first, then validate the response data.
9. REST API Testing Methods
● Browser Addons
● CURL
● Write Your Own Code
○ requests module
requests.get
requests.put
requests.post
requests.delete