© Paul Redmond 2016

Paul Redmond, Lumen Programming Guide, 10.1007/978-1-4842-2187-7_6

6. Responding to Errors

Paul Redmond

(1)Phoenix, Arizona, USA

During your work on the Book API in Chapter 5 it became evident that you need to start using a separate test database. You also don’t have very good error responses for API consumers yet. Responding to a client with an HTML error that expects JSON is not going to cut it anymore. When an API consumer interacts with your API, you want to respond with the correct Content-Type header. For now, you will assume all of your consumers want JSON, and in my experience, JSON is typically what consumers want.

Test Database

The main focus of this chapter will be error responses, but before you work on error responses ...

Get Lumen Programming Guide: Writing PHP Microservices, REST and Web Service APIs 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.