Postman is an API testing environment. cURL is a command line tool for transfering data via URLs. When it comes to REST APIs, we can use Postman as a GUI (graphical user interface) and cURL as a CLI (command line interface) to do the same tasks.

Prerequisites

If you don’t yet understand REST or know how to use REST APIs, please read Understanding REST and REST APIs.

Goals

I’m going to demonstrate how to do GETPOSTPUTPATCH, and DELETE requests via Postman and cURL. If you don’t have Postman, simply download it from the website. cURL should already be installed in your macOS or Linux environment.

Endpoints

I’m going to use JSON Placeholder, an awesome example site for testing API calls. You can follow along and paste all the commands into your terminal to see what response you get.

Here is the map of methods to endpoints we’ll be using. /posts means all, and the 1 in /posts/1 represents /posts/{id}, so ID number1.

GET https://jsonplaceholder.typicode.com/posts

POST https://jsonplaceholder.typicode.com/posts

PUT https://jsonplaceholder.typicode.com/posts/1

PATCH https://jsonplaceholder.typicode.com/posts/1

DELETE https://jsonplaceholder.typicode.com/posts/1

You can click those URLs to see the GET values they provide to the browser. You can use the browser for GET, but you’ll have to use cURL or Postman to POST, PUT, PATCH or DELETE.

#rest api #reference #postman #curl

How to Make API Requests with Postman or cURL
15.45 GEEK