Chapter 13. Building an API
This chapter covers
So far, you’ve dealt with handling HTML requests that presumably come through a web browser. A request comes in for a web page, and your Phoenix application handles the request and returns valid HTML markup for the user’s browser to render. But Phoenix is also excellent at returning other kinds of responses. In this chapter, we’ll look at handling requests for JSON by responding with JSON.
This kind of request/response cycle is something you’ll often see in an API application. These could be mobile applications or even third-party integrations. In both cases, they consume the data that your application controls and then do whatever they need with that data, whether that’s populating mobile application fields or using it for deep learning. It’s up to the end user how they use the data—the API application just makes it available.
For your Auction application, you’ll make data regarding auction items available. Each item will also return the collection of bids made on that item. Going even deeper into the associations, each bid will return minimal information about the user that made the bid. All this will be returned in JSON format for end users to consume however they wish.