So far, our web service can perform the basic operations on a user profile. In this chapter, we will extend the user profile service to also handle a user's profile image. During the course of this chapter, you will learn how you can process even very large files using PHP streams.
Basically, in a RESTful application, you can treat an image just as any other resource. You can create and update it using POST
and/or PUT
operations, and you can retrieve it using GET
. The only difference is the chosen representation of the resource. Instead of JSON encoding using application/json
as a Content-Type, you will now work with resources that have a JPEG or PNG representation, with their respective image/jpeg
or image/png
content types.
At this point, it will be useful to understand how the PSR-7 standard models HTTP requests and response bodies. Since technically, each message (both request and response) body is just a string of characters, these could be...