I. What is an interface

An interface is a protocol used to define a program that describes a set of related behaviors that can belong to any class or structure.

An interface is a set of rules that specifies the set of rules that the class or interface that implements the interface must have. “If you were… Must be able to…” The idea of.

An interface is an abstract representation of the same kind of thing on a granular view. Because the concept of “like” is relative, it varies from granular view to granular view.

Why use interfaces? Instead of implementing it directly?

Interfaces are not always used from a design standpoint. Interfaces, like other Python syntactic phenomena, make up the entire Python language.

The meaning of interface is abstract, not details, so that the same kind of things in the same height is universal and substitutable.

In system analysis and architecture, a distinction is made between layers and dependencies, where each layer does not provide services directly to its upper layer (that is, not directly instantiated in the upper layer), but exposes its interface functionality only to the upper layer by defining a set of interfaces that depend only on interfaces to the lower layer, not concrete classes.

  • Enhanced system flexibility When the lower layer needs to change, the upper layer does not need to change as long as the interface and interface functions remain unchanged. Even can not change the upper code will lower the replace, as we will be a WD 60 gb hard drive for a Seagate 160 gb hard drive, computer without doing any changes in other places, but the original hard disk pull down, the new hard disk on line, because other parts of the computer does not depend on the specific hard drive, but only rely on an IDE interface, As long as the hard disk implements this interface, it can be replaced.
  • Developers of different components or levels can work in parallel, just as those who build hard disks do not need to build CPUS, and do not need to build displays. As long as the interfaces are consistent and the design is reasonable, they can be developed in parallel, thus improving efficiency.

So when do you use it and when do you not use it? In a common three-tier architecture, the following layers are described respectively:

  • The interface layer is also the display layer, which is directly presented to the user. Different software may have different presentation methods, such as Web, WinForm, or even mobile APP. At this level, I think there is no need to write too many interfaces.
  • Business logic Layer This layer, business logic, can use interfaces as needed. If you’re reading or writing directly to a database or something, use the interface that calls the database access layer. If you are interacting with multiple third-party interfaces, you need interfaces, implemented separately by different channels.
  • Data access Layer The data access layer, preferably using interfaces, such as database access, which can be implemented according to different databases to provide services to the business logic layer.

Type of interface request

Http1.0 defines three request methods: GET, POST, and HEAD

Http1.1 adds five new request methods: Options, PUT, Delete, Trace, and connect

Get: Requests the specified page information and returns the entity. Get, arguably the most common, is essentially a request sent to retrieve a resource on the server that is returned to the client through a set of HTTP headers and render data.

Head: Similar to a GET request, except that the response is returned without the specified content and is used to retrieve the header.

Post: submits data to the server. This method is so versatile that almost all commit operations rely on it.

Put: Data sent from the client to the server replaces the contents of the specified document. Put and POST both send data to the server. There is an important difference between them. Put usually specifies the location of the resource, while POST does not.

Delete: requests the server to Delete the specified page. Delete a resource

Connect: reserved in the HTTP1.1 protocol for proxy servers that can pipe links.

Options: allows clients to view server performance. Returns the HTTP request method supported by the server for a particular resource.

Trace: displays the requests received by the server for testing or diagnosis.

4. Interface specification and interface documentation

The importance of interface specifications

In order to better cooperate between web/ APP developers and backend interface developers, we need to develop interface specifications. Interface is an inseparable link between the Web/APP end and the server end. The standardization of interface will directly affect the efficiency and quality of the docking process between the two sides. For the purpose of fast and efficient development and avoiding the error rate in the process of docking, the interface should have standard constraints.

Interface documentation

Background interface personnel and mobile developers must not cooperate with the interface document this weapon! For medium and large projects, an interface may contain hundreds of fields. If there is no interface document and only two heads communicate, it is estimated that several interfaces can be completed in a day.

What are the forms of interface documentation?

1 Excel, Word and other documents.

2 Interface for managing open source websites

Interface documentation and interface test tool — APIPost

It can not only test the interface but also generate documents according to the tested interface. There are online documents, offline documents such as: HTML \ Markdown and Word format documents, directly generated without their own handwriting.

! [](https://pic3.zhimg.com/80/v2-67b8057ee00e3915f1f38938ec690e92_720w.jpg)
! [](https://pic3.zhimg.com/80/v2-02ea0ba5ff670f5b56e6dbfb9654a696_720w.jpg)
! [](https://pic3.zhimg.com/80/v2-f4806c99937361c02edd1ba2588c297a_720w.jpg)

ApiPost – An API debugging and management tool that generates documentation directly www.apipost.cn