Chapter 13. Building an API

This chapter covers

  • Scoping different types of requests via the router
  • Responding to JSON requests with JSON
  • Using render_many/4 and render_one/4 to render collections of resources

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 ...

Get Phoenix in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.