Skip to content

Commit

Permalink
API
Browse files Browse the repository at this point in the history
  • Loading branch information
Asabeneh committed Jul 10, 2021
1 parent d2b1c9b commit bc45688
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions 28_Day_API/28_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<sub>Author:
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> First Edition: Nov 22 - Dec 22, 2019</small>
<small>Second Edition: July, 2021</small>
</sub>

</div>
Expand Down Expand Up @@ -38,29 +38,38 @@

## API

Application Programming Interface(API). The kind of API will cover in this section is going to be Web APIS.
API stands for Application Programming Interface. The kind of API we will cover in this section is going to be Web APIs.
Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets, which also is a Service Level Agreement (SLA) to specify the functional provider and expose the service path or URL for its API users.

In the context of web development, an API is defined as a set of specifications, such as Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, usually in an XML or a JavaScript Object Notation (JSON) format.

Web API has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources.
Social media services, web APIs have allowed web communities to share content and data between communities and different platforms. Using API, content that is created in one place dynamically can be posted and updated to multiple locations on the web.
For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data. Many applications provide API end points. An example [API](https://restcountries.eu/rest/v2/all).
In this section, we will cove a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.

Social media services, web APIs have allowed web communities to share content and data between communities and different platforms.

Using API, content that is created in one place dynamically can be posted and updated to multiple locations on the web.

For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.

Many applications provide API end points. Some examples of API such as the countries [API](https://restcountries.eu/rest/v2/all), [cat's breed API](https://api.thecatapi.com/v1/breeds).

In this section, we will cover a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.

## Building API

RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using python flask and mongoDB. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from database.
RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using Python flask and mongoDB database. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from a database.

To build an API, it is good to understand HTTP protocol.
To build an API, it is good to understand HTTP protocol and HTTP request and response cycle.

## HTTP(Hypertext Transfer Protocol)

HTTP is an established communication protocol between a client and a server. A client in this case is a browser and server is the place where you access data. HTTP is a network protocol used to deliver resources which could be files on the World Wide Web, whether they're HTML files, image files, query results, scripts, or other file types.
HTTP is an established communication protocol between a client and a server. A client in this case is a browser and server is the place where you access data. HTTP is a network protocol used to deliver resources which could be files on the World Wide Web, whether they are HTML files, image files, query results, scripts, or other file types.

A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then sends responses back to the client.

## Structure of HTTP

HTTP uses client-server model. An HTTP client opens a connection and sends a request message to an HTTP server and the HTTP server returns message which is the requested resources. When the request response cycle completes the server closes the connection.
HTTP uses client-server model. An HTTP client opens a connection and sends a request message to an HTTP server and the HTTP server returns response message which is the requested resources. When the request response cycle completes the server closes the connection.

![HTTP request response cycle](../images/http_request_response_cycle.png)

Expand All @@ -71,7 +80,7 @@ The format of the request and response messages are similar. Both kinds of messa
- a blank line (i.e. a CRLF by itself), and
- an optional message body (e.g. a file, or query data, or query output).

Let's an example of request and response messages by navigating this site:https://thirtydaysofpython-v1-final.herokuapp.com/
Let us an example of request and response messages by navigating this site:https://thirtydaysofpython-v1-final.herokuapp.com/. This site has been deployed on Heroku free dyno and in some months may not work because of high request. Support this work to make the server run all the time.

![Request and Response header](../images/request_response_header.png)

Expand All @@ -83,9 +92,8 @@ A request line has three parts, separated by spaces:
- method name(GET, POST, HEAD)
- path of the requested resource,
- the version of HTTP being used. eg GET / HTTP/1.1
-

GET is the most common HTTP to get or read resource and POST a common request method to create resource.
GET is the most common HTTP that helps to get or read resource and POST is a common request method to create resource.

### Initial Response Line(Status Line)

Expand All @@ -101,7 +109,7 @@ The initial response line, called the status line, also has three parts separate
The most common status codes are:
200 OK: The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body.
500 Server Error
A complete list of HTTP status code can be found [here](https://httpstatuses.com/)
A complete list of HTTP status code can be found [here](https://httpstatuses.com/). It can be also found [here](https://httpstatusdogs.com/).

### Header Fields

Expand Down

0 comments on commit bc45688

Please sign in to comment.