top of page

HTTP Methods In REST API- Get REST API Assignment Help

RESTful services give the flexibility to create application involving following operations (also know as CRUD)

  • Create

  • Read

  • Update

  • Delete

There are five methods of HTTP used in REST API.

1. Get

2. Post

3.Put

4.Patch

5. Delete


1. Get Method

HTTP GET method used to get information from the REST API.

If Get method is called multiple time ,it will give same data all time.

  • HTTP GET request should return 200(OK) Response if it finds data.

Example:

http://localhost:5000/users/api/get

Output :

[
    {
        "_id": "61a75a09cadcdb2cb8a862a3",
        "name": "abhi1",
        "email": "singh1@gmail.com",
        "__v": 0
    },
    {
        "_id": "61a75aa9e8b2a472084a52e5",
        "name": "Abhi2",
        "email": "singh2@gmail.com",
        "__v": 0
    }
]

List of all users present in database is in output.


2. Post Method

This method in the REST API should only be used to create a new resource. To pass data from client-side to server-side POST method is used.

Example:

http://localhost:5000/api/create

Data passed.

{"name": "abhi8",
        "email": "singh8@gmail.com" 
}

Output :

Successful register.


3. Put Method

Use PUT APIs primarily to update an existing resource (if the resource does not exist, then API may decide to create a new resource or not).

Example:

http://localhost:5000/api/update-employee-id
    

Data Passed:

{"name": "abhi08",
        "email": "singh08@gmail.com" 
}

Output :

Successfully updated.


4. Patch

HTTP PATCH requests are to make a partial update on a resource. PATCH will not create any new data if no data is found.

Example:

Data passed

{
"name": "abhi8",
        "email": "singh8@gmail.com"
        }

Output: If found then successfully updated otherwise not found


5. Delete

To delete data from database DELETE method is used.

Example:

Id is passed through url which is to be deleted.

Output:

One record deleted.






Are you new to react.js or Just started learning and struggling with react.js project? We have team of react.js developer to help you in react.js project, assignment and for learning react.js at affordable price.

bottom of page