HTTP and the Methods we use in Web APIs

We all know what HTTP is by now. (If you don't see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview)

If I ask you to perform a GET request against www.google.com using netcat, you should be able to do that as follows:

nc www.google.com 80
GET / HTTP/1.0\r\n
\r\n

Most of you are familiar with this sequence from your networking class.

Can you use netcat to do that? If you haven't tried it or haven't succeeded, STOP! Get and do it now or get help before you continue.

HTTP Methods

Although, GET is by far the most used method, it is important to know exactly what it and each of the other methods mean/do.

HTTP Methods (RFC 7231, section 4 and RFC 5789, section 2):

Of these nine methods, web APIs usually only use GET, POST, PUT, DELETE, PATCH

GET

GET is the method we use to retrieve web pages from a regular web application. But that is not technically what it does. The GET METHOD requests a representation of the specified resource. GET performs no side effect (or shouldn't) and thus makes no change to the state of the resource. That is we use GET to retrieve data and nothing else.

There are several tools for testing web sites or RESTful services a.k.a web APIs. One tool that I'm going to use throughout this presentation (and course) is curl. curl is available on both Windows and Unix like operating systems. The examples here are completed in the Windows Subsystem for Linux (WSL).

# Adding a Temperature to the list

curl -i --request POST --header "Content-Type: application/json" -d '{"date":"2020-08-26T00:00:00",peratureC":15,"summary":"Cool"}' http://localhost:4829/weatherforecast/AddDailyTemp