Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Building an API in Code

Phoenix comes default with an API Pipeline that we can start with as part of our application. They do this to highlight how easy it is to introduce new pipelines in Phoenix to be able to handle different paths that a request needs to take to build a valid response. Let's open up our router file and take our first peek at API-specific code, which sets up our base API pipeline. Instead of going through the normal browser pipeline (which has other work it needs to do to make the browser even work), the API essentially just needs to make sure that the format being sent is what the API can accept. For purposes of our API, all we need to accept is JSON.

Let's open up lib/vocial_web/router.ex and take a peek:

 pipeline :api ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content