Over the last couple years, I’ve really taken an interest in HTTP APIs.
I’ve been meaning to post about my experiences developing an HTTP APIs. It’s been an interesting last couple of years and I think there is quiet a bit to share.
I can only speak from my experiences and give some of the context about my situations. Hopefully you can relate and translate it to your own projects and make a determination if what I struggled with is beneficial in your context.
There were four major pain points that I ran into developing our HTTP API and Clients.
- Unable to change internal data structures that got exposed/serialized to Clients
- Unable to change endpoint paths/routes
- Endpoint documentation (incoming and outgoing payloads)
- Workflow logic living on the client
Sometimes all you need is to do CRUD. Sometimes that’s the last thing you should be doing.
Most examples and getting started tutorials usually demonstrate exposing your database structure and provide GET/POST/PUT/DELETE as away of performing CRUD.
You basically end up with HTTP endpoints that are a 1:1 mapping with a database entities.
This also makes it incredibly hard to change your API.
Go beyond serializing a database row into JSON
I’ve realized that developing an HTTP API is not much different than developing a regular HTML Website.
I started developing my HTTP APIs like I would if I were creating a static HTML or server side rendered HTML web application. This means bringing the concepts we’ve been using for ages with HTTP and HTML such as links and forms.
(Un)Surprisingly, this lead to several benefits. First, our API clients could consume our API with ease. Second, they became dumb. Workflow or business logic stayed on the server and didn’t leak to the client.
This series of posts is going to cover some misconceptions I had in regards to HTTP APIs and REST.
Producing an HTTP API using Hypermedia and various media types.
Consuming an HTTP API that uses Hypermedia.
How you can use CQRS and Hypermedia together.
Similar to my Fat Controller CQRS Diet series, I’m going to convert an existing web application. Currently I’m thinking of using the MVC Music Store again. If anyone has any other suggestions or recommendations about this series, or the sample project to convert, please leave comment or let me know on twitter.
- Building a Self Descriptive HTTP API in ASP.NET Core
- Object as Resource
- Hypermedia Clients