Justin introduces the basic concept of an API and why you might want to build one, as you explore the API that you build in this course.
Before we dive into building our Laravel API, let's talk about the basic ideas of what is an API, what we use it for, and when you might need one. An API stands for an Application Programming Interface. It's a tool to allow other programmers to build off of, to build their own software. APIs can be used by other in house teams or by teams outside of your own company. Sometimes you may even both build the API yourself and implement the API.
APIs are designed to allow you to separate the front end implementation details from the back end. An API built this way will allow you to support multiple implementers or multiple teams to implement an application in their own specific way. Twitter, for instance, has an API that allows multiple Twitter clients to exist. They all implement the same Twitter API, but each implements it in their own unique way. You can even build API clients that only use part of the API.
In Twitter's case, you may make a Twitter client, for instance, that only supports direct messages, but nothing else. APIs also shouldn't just be BREAD and CRUD operations. Or they shouldn't just implement an index, an add, an edit, a view, and a delete operation. The API can, and should, hide the actual underlying database and any possibly tricky logic behind an easy to read and program against interface. APIs can and do support multiple standards such as REST, RPC, GraphQL, SOAP, and basically anything you want the API to do, you can write your API to support.
Twitter has an API that is used both publicly for the web interface version of the Twitter website, as well as an API that is used by the hundreds of Twitter clients on multiple devices and platforms. Google Maps here can be used in multiple formats as well. We can display maps, validate addresses, get directions, and dozens of other use cases. The point here is that APIs come in all flavors and different sizes. We're going to build a simple API to support creating and managing polls.
We'll also manage poll questions and their corresponding answers. We won't build a front end interface for this API, but let's explore a bit of what our API might look like if we implemented a front end for it. We'll have an API endpoint to build that interface for viewing questions for a particular poll. You'll be able to build an endpoint to be able to add answers for those questions. So you'll be able to create polls with their corresponding questions and you can then answer those questions to complete a poll.
We'll finally build in some authentication for our API so we could assign the answers for our poll to a certain user if we wanted to. Or you could build the API to allow only certain users to access certain polls. You should keep in mind with building out an API, they typically are only one part of a tool, but not the whole tool. Sometimes you'll want or need to provide other tools. If you're building an API to power an internal front end, you'll still need to write that particular front end. If the API is designed for external teams to use and consume, you might want to build out a library for the API.
That way it's easier for people to get started using your API. APIs are a complicated topic. You might want to look at a few other courses if you feel uncomfortable with the idea of forging ahead with this course right away. My course covering Consuming RESTful APIs in PHP with Guzzle may give you some basic ideas around working with APIs as a consumer and why you might use them. The courses on Designing RESTful APIs and API Testing and Validation can be helpful to understand some of the finer details around designing and testing APIs.
There are also many other API building courses in the library if you want to take a look at building APIs with tools other than Laravel.
- Reviewing the basics of an API
- Basic pieces of the Laravel framework
- Reading, adding, editing, and deleting a record
- API errors and exceptions
- Transforming your API data
- Returning nested and sideloaded data
- Creating a logging middleware
- Authenticating to your API
- Basic and advanced endpoint testing