On this page:
Add a new user to the Orca Sightings service: a tutorial
This tutorial should take you about 15 minutes to complete.
Before you begin
Make sure you’ve set up your environment and started the service using json-server.
Step 1: Submit a cURL or Postman request with the POST method
To use cURL:
Enter the following command to add a new user named Ben Waters.
curl -X POST \
-H "Content-Type: application/json" \
-d '{ "last_name": "Waters", "first_name": "Ben", "email": "ben.waters@gmail.com" }' \
http://localhost:3000/users
In this example, -X specifies the method, -H indicates the header, and -d specifies the data.
To use Postman:
- Select POST and enter
http://localhost:3000/users/. - In the Header tab, select Content-Type and then application/json.
- In the request body, select Body > raw > JSON and enter:
{
"last_name": "Waters",
"first_name": "Ben",
"email": "ben.waters@gmail.com"
}
Step 2: Make sure the service created the new user
Both of the previous examples should return the information from the request body plus a unique ID.
{
"last_name": "Waters",
"first_name": "Ben",
"email": "ben.waters@gmail.com",
"id": 5
}
The id might be different if you’ve completed other tutorials first.
You’ve completed this tutorial. Next, try other tutorials or refer to the reference topic POST /users.