What is an API?

As long as we’re programming, we’re constantly designing apis.

An API can simply be a function called, an interface.

Abstractly, an interface is a cohesive system that exposes everything to the outside world, including but not limited to:

Call method: such as lib library or HTTP interface.

Calling conventions: lib function signatures or HTTP parameters, HTTP methods or headers, long and short links, etc.

Dependencies: For example, interface calls need to involve third parties or other preparatory work, etc.

API, like a person, when we are dealing with an API needs to understand the characteristics of the preferences, etc., some people get along well, but some people let people very headache, especially when you have to deal with him, and, if you had to deal with him, to change his temperament is very painful, “boys will be boys”, API, too, Once released, the cost of change is very, very high.

A good API should have:

Easy to learn: Easy to use even without documentation.

Not easy to misuse: This is important to reduce the mental burden of the user.

Easy to meet requirements: API completeness and orthogonality. It can easily meet the requirements. Completeness ensures the integrity of functions, and orthogonality ensures the simplicity of interfaces. It is not necessary to provide interfaces for all requirements, but to be combined by users.

Easy to expand

How to design a good API?

Specificity: The functionality of an API should be single and easy to explain and understand so that it can be used better.

Be as small as possible: Small has many advantages and is easy to understand and maintain.

Minimize external dependencies: reduce consumer costs.

Design is not affected by the implementation: do not disclose implementation details to the user, may be less exposed, not only internal details, for unnecessary interface as far as possible do not publish, such as the use of a few functions, can temporarily not expose the interface.

Good naming: Try to be self-describing.

Well-documented

Consider the performance

Thanks ~ 

AD:




PHP Engineer subscription number


PHP team development encountered those pits, see how I solve?