Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, and hypermedia information systems and is one of the primary methods for communication with the API. In this case, our focus will be leveraging HTTP from a programmatic perspective rather than as an access mechanism, which is the case with the World Wide Web. Hypertext is structured text using logical links between nodes containing text (also called hyperlinks) and HTTP is the protocol to enable exchange or transfer of hypertext.
HTTP has two types of messages:
Requests from a client to a server, consisting of:
- Request Line: The request line begins with the method token, followed by the Request-URI and the protocol version.
- Request Uniform Resource Identifiers (URI): The URI is a set of string of characters used to identify the name of a resource. The most commonly used URI is in the form of the Uniform Resource Locator (URL). For example www.cisco.com
- Request Method: The request method indicates the method to be performed on the resource identified by the given Request-URI. Here is a list of supported methods:
- GET - The action of "getting" the information which is identified by the Request-URI
- HEAD - Similar to the GET method but it includes the transfer of the status line and the header section only
- POST - Used to send data to the server. Examples include loading a new configuration or querying the state of the network element
- PUT - Replaces all the current representations of the target resource with the uploaded content
- DELETE - Requests the origin server delete the resource identified by the Request-URI
- OPTIONS - Requests for information about the communication options available on the Request-URI
- TRACE - Invokes a remote, application-layer loop-back of the request message
- CONNECT - Establishes a tunnel to the server identified by a given Request-URI
Responses from a server to a client in response to a request, consisting of:
- Status Line: This is the first line of the Response Message which contains the protocol version follow by the status code.
- 503 – Services Unavailable
- 500 – Internal Server Error
- 404 – Not Found
- 403 – Forbidden
- 400 – Bad Request
- 301 – Moved Permanently
- 201 – Created
- 200 – OK
- Message Body
The following diagram describes a Client Request and the Server Response communication.
HTTP Client Request with Response Code
HTTP Client Request with Response Code