[PHP] [API] Chapter8: Implementation

Source: Internet
Author: User
[PHP] [API] Chapter8: Implementation we now have at least an introduction to API. How can we use our knowledge? In this section, we explore how to turn knowledge into software that can work.

From planning to products

As we can see, an API interaction involves two aspects. Although we discuss it at the code level, what we really want to say is that we need two programs to implement the API. A program follows the API rules to implement the API. As in our pizza shop example, a client can use the correct headers and data format to send requests and become a client that implements APIs.

Server programs are the responsibility of API companies to release. Chapter 6 reviews the API design process. After planning, the next step is to develop software for the company through design. The last step is to put the program on the server,

With the server software, the company releases API documentation. This document is one or more-typical web pages or PDF files-explains how to use APIs. It contains information like what authentication scheme is used, which endpoints are available, and data formatting. It may also include response, code snippets, interactive console, and existing endpoints. Documentation is very important because it serves as a guide for building clients. This is why some people use APIs to learn how APIs work.

With the documentation in hand, there are some APIs you can start to use as the client. Now let's explain the third.

HTTP client

An easy way to start using APIs is a general program that allows you to quickly build HTTP request tests. You specify the URL, headers, and subject, and the program sends it to the correctly formatted server. These types of projects include Web applications, desktop applications, and Web browser extensions.

The advantage of using a common HTTP client is that you do not need to know how the program is used. With the ability you get through this course, you can now read a company's API documentation and find out the requests you need to get the data. This small learning curve allows general programs to quickly explore one-time tasks.

Write code

To truly leverage the power of API, you will eventually need to customize the software. This requires programming. As a discipline, we will not try to cover everything in software development, and provide you with some guidance on what an API client contains.

The first requirement is to understand some familiar programming languages. There will be a lot here, and each has its strengths and weaknesses. For the sake of simplicity, you may better stick to an interpreted language (similar to JavaScript, Python, PHP, Ruby, etc.), rather than a compiled language (C or C ++ ).

If you are not sure which language to choose, a good way to narrow down the scope may be to find an API you want to implement and check whether the company provides the API client library. The library is released by the API owner. it is an API that has implemented the client. Sometimes the library is downloaded separately or bundled with the SDK (software development kit. The library can save you time. because you do not need to read the API documentation or the format required by HTTP requests, you can easily copy and paste several lines of code and a working client.

In the language you are looking at, you need to decide where the code runs. If you automate your tasks, it is acceptable to exercise on a work computer. More often, you want to run code on a computer instead of a server. There are many solutions, including cloud services (such as Amazon Web Services), or even running your code in the shared host environment on your own physical servers in the data center.

The third important decision is to figure out what you will do with data. It is easy to save the results to a file, but if you want to store the data in the database or send it to another application, it becomes more complicated. It is also challenging to send data from a database to an ap I. At this point, we can pause and remind you not to be intimidated by all the new information. You should not expect your first attempt to implement all the APIs. Some people can help you (open-source communities, developers, and potential project partners) and a large number of online learning resources.

Once you understand the basic knowledge, there are many rich topics about software development, you will understand. Now, if you are learning a programming language, getting a library, and running successfully, you should celebrate. You will do more APIs in the way you are good.

Try Zapier

If encoding exceeds your current skill or time limit, there is an excellent tool we know that it allows you to easily interact with APIs. As you know, it is Zapier. Our development environment provides you with an API that you can use on Zapier as an APP. By pressing a button and submitting an application, you can implement almost any API you want.

We have done a lot of projects, but you are more convenient to use the development platform. Zapier has a place to put forward the request code. all you need to do is fill in the details. Consider using the environment, just like using a common HTTP client; you tell us an endpoint and we will do the rest. The additional benefit is that once you have Zapier interacting with APIs, you have a lot of options to use the returned data. In addition, if you encounter a problem, we have a friendly support team to help you solve the problem.

Summary

We have been learning for a long time. from the very beginning, "What is a client ?", By the end, you can build a client. Even if you decide not to implement an API, we hope you will feel comfortable when they are talking about it in a timely manner. Now you know what an API is, what it can do, and how it brings benefits to a company.

Maybe you run a company and check the value of providing APIs to customers. Or, maybe you often do this, and you are very happy to be automatically annoying, time-consuming tasks. In either case, we hope you can find the valuable knowledge you have gained. Share this course with others. you think you can benefit from it and spread it.

Chapter 8 Summary

This chapter describes how to design APIs into software. We talked about several ways to use APIs.

This is what we learned:

  • Implementation: Write a software that complies with API rules
  • Document: Webpage and PDF that explains API rules
  • Library: The code released by the API publisher implements the client part of the API.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.