Session 1.2: Postman
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 on the internet, the HTTP request methods/verbs, the HTTP request and responses, and response status codes.
- Install Postman
- Run the following requests with Postman:
1. Method: GET URL: https://jsonplaceholder.typicode.com/posts
Does the request contain a body? What do you see in the response body?
Paste https://jsonplaceholder.typicode.com/posts into the address bar of your browser, what do see? What does that mean?
2.Method: GET URL: https://jsonplaceholder.typicode.com/posts/{id}
Note: replace {id} with a valid Id (e.g., 1 - 99)
What do you see in the response body? What is the status code?
3.Method: GET URL: https://jsonplaceholder.typicode.com/posts/101
What is the status code?
4.Method: GET URL: https://jsonplaceholder.typicode.com/comments?postId=1
What do you see in the response body?
Note: "?" stands for the start of a query. Accordingly, /comments?postId=1
means return all comments on post with Id =1 in this context.
5.Method: POST URL: https://jsonplaceholder.typicode.com/posts
Headers: { "Content-type": "application/json; charset=UTF-8" }
Body: { "userId": 1, "title": "PostTitle", "body": "PostBody" }
What are the main differences between GET and POST?
6.Method: PUT URL: https://jsonplaceholder.typicode.com/posts/5
Headers: { "Content-type": "application/json; charset=UTF-8" }
Body: { "id": 1, "userId": 1, "title": "UpdatedTitle", "body": "UpdatedBody" }
Tasks:
Try to run the following requests with Postman by yourself. Do not forget to replace {id} with a valid number. Try to run each request with several different {id}, and check the response head, body, and code.
1. Method: GET URL: https://jsonplaceholder.typicode.com/posts/{id}/comments
2. Method: GET URL: https://jsonplaceholder.typicode.com/posts?userId={id}
3.Method: PATCH URL: https://jsonplaceholder.typicode.com/posts/{id}
Headers: { "Content-type": "application/json; charset=UTF-8" }
Body: { "title": "A New Title", }
4. Method: DELETE URL: https://jsonplaceholder.typicode.com/posts/{id}