Build APIs You Won't Hate

Everyone and their dog wants an API, so you should probably learn how to build them.

Tasked with building an API for your company but don't have a clue where to start? Taken over an existing API and hate it? Built your own API and still hate it? This book is for you.

This book has been up on the LeanPub top 10 for most of its lifetime, and was #5 Best Selling Book of 2015, so it can't be too bad.

Available in PDF, ePUB, Mobi, Kindle & Paperback.

Get pragmatic API, HTTP and REST info monthly!
Also, if a mailing list is not enough for you, we have a Slack channel. Get help with your API, REST and HTTP questions.

What the book covers


Naming things is hard, and working out how to structure your endpoints can be tough. Understand the benefits of plural v singular, collections, resources, sub-resources, sub-collections, etc.

Input and Output

Learn which data formats are nice to work with, and why form data is so entirely useless. Compare Facebook, Twitter and existing standards like JSON-API.

Status Codes, Errors and Messages

Look at what makes a good error message, making it understandable for humans and computers alike with the inclusion of codes, documentation links, and usage of standards.


Working with APIs can be a little confusing at first, especially if you're trying to use the browser or Curl. This chapter outlines some powerful tools to make it easy as pie.


Shoud you use HTTP Basic, HTTP Digest, OAuth 1.0a or OAuth 2.0 to secure your API? The answer is probably OAuth 2.0, but find out a huge load of pros and cons on each of them.


Regardless of whether you decide to keep an API private or release it to the general public, documentation is incredibly important. These tools will make documentation much easier to maintain and manage.


Copies sold





About the book

API development is becoming increasingly common for server-side developers thanks to the rise of front-end JavaScript frameworks, iPhone applications, and API-centric architectures. It might seem like grabbing stuff from a data source and shoving it out as JSON would be easy, but surviving changes in business logic, database schema updates, new features, or deprecated endpoints can be a nightmare.

After finding many of the existing resources for API development to be lacking, Phil learned a lot of things the hard way through years of trial and error. This book aims to condense that experience, taking examples and explanations further than the trivial apples and pears nonsense tutorials often provide.

Phil worked primarily as an API developer for the last three years. One horror was managing an API built in FuelPHP by a freelancer at the million dollar startup he joined. It was utilizing a then deprecated ORM which had been hacked to death by the previous developer, so took the time to delete that mess and build the next version in Laravel, leveraging it's simple routing, database migrations, schema, seeding, etc. When the following major version of the API was built no rewrite was required, and both managed to live side-by-side on the same "API" servers.

By passing on some best practices and general good advice you can hit the ground running with API development, combined with some horror stories and how they were overcome/avoided/averted. This book will discuss the theory of designing and building APIs in any language or framework, with this theory applied in PHP-based examples.

Some of the more advanced topics covered here are endpoint testing, embedding data objects in a consistent and scalable manner, paginating responses (including embedded objects) and hypermedia "HATEOAS" controls.

People who no longer hate their APIs

Just buy the damn book

About Phil Sturgeon

Over the last five years I've worked as a freelancer, consultant, Head of API, and CTO, for several API-centric technology startups. The most recent, Ride, has given me the chance to work with several amazing developers, including several Rails API contributors. Ride let me share our API experiences at conferences world-wide, which is an amazing opportunity to educate others on a topic I'm incredibly passionate about.

Spending that much time building APIs means I have a long list of ways to make them not suck, and I would like to that with you lot. The book covers everything learned from years of doing this day in day out, and it tries to keep it light and breezy: through what could otherwise be some rather dull topics.

For more about APIs, you can check out my blog, and specifically the #api tag.