Session 2.2: Postman - [Pre Lab]
Postman is an API platform that helps developers to design, build, and test their APIs. We will use it to better understand the API architecture, how we can fetch resources, the HTTP request methods/verbs, the HTTP request and responses, and response status codes.
- Install Postman
Postman interface
We can run the following requests with Postman to test our Rest API project:
1. GET all products
Method: GET URI: http://localhost:8080/products
2. GET a product by id
Method: GET URI: http://localhost:8080/products/{id} Note: replace {id} with a valid Id (e.g., 01, 02, 03, i.e., http://localhost:8080/products/01)
3. Add a new product
Method: POST URI: http://localhost:8080/products Headers: { "Content-type": "application/json" } Body: { "id": "04", "name": "new light vehicle", "type": "Light another new", "description": "Can also be used for light work", "price": 1250 }
4. Try GET all products again to see the newly added product.
5. Update an existing product
Method: PUT URI: http://localhost:8080/products/{id} Example: http://localhost:8080/products/04 Headers: { "Content-type": "application/json" } Body: { "id": "04", "name": "new light vehicle", "type": "Light another new", "description": "Updated - Can also be used for light work", "price": 1290 }
6. Try GET all products again to see the updated product.
7. Delete a product
Method: DELETE URI: http://localhost:8080/products/{id} Example: http://localhost:8080/products/04
8. Try GET all products again to see whether the product was deleted