Chapter 13. Creating a RESTful JSON API with Swagger
This chapter covers
- API basics and construction styles
- Adding an HTTP API to the Hacker Tracker
- Refactoring code to remove trait duplication
- The Swagger documentation framework
- Annotating the Hacker Tracker API using Swagger
- Securing your API with HMAC
Scalatra is commonly used as a way to build HTTP application programming interfaces (APIs). An API is a way for one computer system to talk to another. It usually exposes business processes and data from one computer system, making it available for another computer system to talk to.
If you’ve done any web development over the past several years, you’ll be aware that large web companies—Google, Facebook, Twitter, Amazon—all have APIs that you can integrate with. This functionality often mirrors what you get from their websites. In the case of Google, for instance, you can send machine-readable requests to and from the Google Maps API, just as you can request human-readable information from the Google Maps web interface. With the web interface, you get back HTML that your browser allows you to read yourself. With the API, you get back JSON or XML responses that your programs can use.
Now that you know what an API is, let’s make one.