This document explains the HTTP protocol, URL structure, request and response cycles, status codes, and HTTP methods, focusing on REST APIs and their role in web communication and data transfer.
This document covers the fundamentals of REST APIs, the HTTP protocol, URL structure, request and response cycles, status codes, and HTTP methods. Readers will learn how web communication works and how REST APIs facilitate data transfer between clients and servers.
The HTTP protocol is a standard for transferring information over the web, including REST APIs. REST APIs operate by sending requests and receiving responses using HTTP messages, often containing JSON data.
A Uniform Resource Locator (URL) identifies resources on the web. It consists of three parts:
| Part | Description |
|---|---|
| Scheme | Protocol (e.g., http://) |
| Base URL | Internet address (e.g., <www.ibm.com>) |
| Route | Location on the server (e.g., /images/logo.png) |
Clients send HTTP requests to servers, which locate and return resources. The request includes a method (e.g., GET), headers, and optionally a body. The response contains a status code, headers, and the requested resource.
1GET /index.html HTTP/1.0
2Host: www.example.com
3
4Response:
5HTTP/1.0 200 OK
6Content-Type: text/html
7Content-Length: ...
8<html>...</html>
Status codes indicate the result of a request:
| Code | Class | Meaning |
|---|---|---|
| 100 | Informational | Everything is OK so far |
| 200 | Success | Request succeeded |
| 401 | Client Error | Unauthorized request |
| 501 | Server Error | Not implemented |
HTTP methods specify the action to perform:
| Method | Description |
|---|---|
| GET | Retrieve data from server |
| POST | Send data to server |
| PUT | Update data on server |
| DELETE | Remove data from server |
REST APIs and the HTTP protocol provide a standardized way for clients and servers to communicate and transfer data. Understanding URL structure, request/response cycles, status codes, and HTTP methods is essential for working with web APIs and building data-driven applications.
(2) The HTTP protocol is used to transfer information over the web, including REST API communication.
(1) A URL consists of scheme, base URL, and route to identify resources on the web.
(4) 100 is informational and does not mean the request failed.
| Method | Description |
|---|---|
| A. GET | 1. Remove data from server |
| B. POST | 2. Retrieve data from server |
| C. PUT | 3. Send data to server |
| D. DELETE | 4. Update data on server |
A-2, B-3, C-4, D-1.
The response header in an HTTP response contains information about the resource, such as content type and length.
True. The response header provides details about the resource returned by the server.
(1) The correct syntax for a GET request is GET /index.html HTTP/1.0.