Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use HTTP POST Method


    The HTTP POST method is used to request the resource process the included request message body representation according to resource specific semantics. HTTP POST is loosely defined by definition, and can be used in many different scenarios, such as creating a new resource based on the request representation, appending data to an existing representation, or generic processing of an HTML form submission. Due to the nature of POST performing arbitrary resource specific processing, it is considered neither ‘safe’, nor ‘idempotent’.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    The HTTP post method is used to perform resource-specific processing of requests. This means it can actually be used in a variety of ways. Let's take a look at the first example, where post can be used to create a new resource. We'll be creating a new GitHub issue using the GitHub API.

    Here, we can see our post request has included a message body and a content type to indicate what is included in our request. This is optional with post requests, and some post requests may not have any message body at all.

    We can see that the GitHub server has responded with a 201 status code, indicating it has successfully created our new issue, and it's indicated the location of that issue, as well as returning a representation of that issue in the response. Post can also be used for other generic request processing. As an example, let's update the assignees of our created GitHub issue.

    Again, we have a request body indicating the assignees we would like to add to our issue. We can see that yet again, the GitHub API has responded with a 200 family status code, as well a location header indicating where our issue is that has been updated. We can also see that the issue itself has been updated to include a new assignee.

    Post requests are not idempotent. We can imagine that our initial request to create our issue, if retried several times, would end up creating multiple duplicate GitHub issues.

    To summarize, HTTP post is used to request resource-specific processing of our request. That can be used to create new resources, or to update or make modifications to existing ones, or request other generic processing.