Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Methods in REST approach

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 448
    Comment on it

    REST (Representational State Transfer) is based on resources and actions. A resource can be an URL referencing a object or any entity on which we want to perform action for example: /listUser or /searchUser. Action can be one of the following:

     

    1) GET: Action GET is used to retrieve data.
    2) POST: Action POST is used to create the data.
    3) PUT: Action PUT is used to update the data.
    4) DELETE: Action DELETE is used to remove the data.

     

    I would like to explain using example. Suppose we have user table in database and we need APIs for developers to perform several actions on it. HTTP actions can be:
    1) Enter the new user details.
    2) Retrieve information of all the user.
    3) Retrieve information of the particular user.
    4) Delete an user.
    5) Update an user record.

     

    Under the REST approach, we have to maintain the endpoints, like /listUsers, /registerUser, and have to name to methods in such a way that one can easily examine which HTTP method will be used to access the URL. For example, we use POST method to register a user as we will have data after a post request which we have to save.

     

    REST conventions for URL requests are:

     

    1) GET /users: Retrieve a list of users from the database.
    2) GET /user/1: Retrieve user data from the database who have id = 1.
    3) POST /user: Create a new user.
    4) PUT /users/1: Update the user details who have id = 1.
    5) DELETE /users/1: Remove user who have id = 1.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: