Chapter 9. Building REST APIs

Most non-developers probably think that creating applications means building either software for your PC or Mac, games, or web pages, because that is what they can see and use. But once you join the developers' community, either by your own or professionally, you will eventually realize how much work is done for applications and tools that do not have a user interface.

Have you ever wondered how someone's website can access your Facebook profile, and later on, post an automatic message on your wall? Or how websites manage to send/receive information in order to update the content of the page, without refreshing or submitting any form? All of these features, and many more interesting ones, are possible thanks to the integration of applications working "behind the scenes". Knowing how to use them will open the doors for creating more interesting and useful web applications.

In this chapter, you will learn the following:

  • Introduction to APIs and REST APIs, and their use
  • The foundation of REST APIs
  • Using third-party APIs
  • Tools for REST API developers
  • Designing and writing REST APIs with Laravel
  • Different ways of testing your REST APIs

Introducing APIs

API stands for Application Program Interface. Its goal is to provide an interface so that other programs can send commands that will trigger some process inside the application, possibly returning some output. The concept might seem a bit abstract, but in fact, there are APIs virtually in everything which is somehow related to computers. Let's see some real life examples:

  • Operating systems or OS, like Windows or Linux, are the programs that allow you to use computers. When you use any application from your computer, it most probably needs to talk to the OS in one way or another, for example by requesting a certain file, sending some audio to the speakers, and so on. All these interactions between the application and the OS are possible thanks to the APIs that the OS provides. In this way, the application need not interact with the hardware straight away, which is a very tiring task.
  • To interact with the user, a mobile application provides a GUI. The interface captures all the events that the user triggers, like clicking or typing, in order to send them to the server. The GUI communicates with the server using an API in the same way the program communicates with the OS as explained earlier.
  • When you create a website that needs to display tweets from the user's Twitter account, you need to communicate with Twitter. They provide an API that can be accessed via HTTP. Once authenticated, by sending the correct HTTP requests, you can update and/or retrieve data from their application.

As you can see, there are different places where APIs are useful. In general, when you have a system that should be accessed externally, you need to provide potential users an API. When we say externally, we mean from another application or library, but it can very well be inside the same machine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72