From the course: Building APIs in PHP Using the Slim Micro Framework
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Create a read-write API
From the course: Building APIs in PHP Using the Slim Micro Framework
Create a read-write API
- [Instructor] In this chapter, we'll focus on turning our read-only API into a read/write API that allows authenticated users to create new messages in the system. While this might seem like flipping a switch and we're done, it's not quite that simple. We need to think about the routes, the payload and parameters that are used, the response codes, and how all this is handled and processed behind the scenes. The first piece we'll talk about is the routes. With those aspects in mind, let's tackle the most visible aspect first, the route. From our previous lab sections, we already have a simple route of GET messages, which allows us to retrieve a list of messages. Since we want to create a new message, that's probably the right endpoint. But now we need the right verb. With regards to HTTP, there are 15 verbs available. There are really only four that we care about for APIs, GET, PUT, POST, and DELETE. GET, which we've already used, lets us retrieve data from the API. Not surprisingly…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.