How come when we use the Fetch API, it requires a significant amount of more input into the function for a POST
request as opposed to a GET
request. This has been a bit of a learning curve for myself. Also, what determines the headers you need to use for a POST
request?
TLDR, POST
has more stuff to it.
GET
and POST
are methods for HTTP Requests. The main ones of interest are:
GET
: get a thingPOST
: make a new thingPUT
: change a thingDELETE
: delete a thingThe most basic form of a GET
is asking a specific URI to send back pre-set data. Also, GET
tends to be the most common use request so most HTTP request-making methods will make this very simple. Thus, GET
is often done with little more than a URI.
In contrast, POST
has a lot going on.
GET
request. This is more specific to Fetch API as it assumes GET
by default so you need to specify in the options that you are using method: "POST"
.body: myData
headers: { 'Content-Type': <MIME type of myData> }
in the options.