13.06.2017.
Tuesday.
API
application programming interfaceFor an API or web service to be RESTful, it must do the following:
- Separate the client from the server
- Not hold state between requests (meaning that all the information necessary to respond to a request is available in each individual request; no data, or state, is held by the server from request to request)
- Use HTTP and HTTP methods (as explained in the next section).
HTTP methods
- GET: retrieves information from the specified source (you just saw this one!)
- POST: sends new information to the specified source.
- PUT: updates existing information of the specified source.
- DELETE: removes existing information from the specified source.
Anatomy of a Request
An HTTP request is made up of three parts:
POST /codecademy/learn-http HTTP/1.1
Host: www.codecademy.com
Content-Type: text/html; charset=UTF-8
Name=Eric&Age=26
- The request line, which tells the server what kind of request is being sent (GET, POST, etc.) and what resource it's looking for;
- The header, which sends the server additional information (such as which client is making the request)
- The body, which can be empty (as in a GET request) or contain data (if you're POSTing or PUTing information, that information is contained here).
POST /codecademy/learn-http HTTP/1.1
Host: www.codecademy.com
Content-Type: text/html; charset=UTF-8
Name=Eric&Age=26
No comments:
Post a Comment