Abstracting Request Keys

TJ Miller
1 min readMar 23, 2018

--

Photo by Matt Thomason on Unsplash

In an API’s codebase its a good idea to abstract the keys for the requests and responses on top of your data layer. This is a key step to making it easier for your codebase to evolve and still uphold your API contract.

In Laravel we have Resource Responses to help abstract our model data for responses. For request data, I wanted a light weight key mapping to help add a little abstraction layer.

First I created a little Request macro:

Now you can use it in your controllers to map from request data to domain data.

One thing I’ll still need to figure out is mutating nested keys, but I’ll cross that bridge when I get there!

--

--

TJ Miller

Fullstack code cowboy, ADHD enthusiast 🙃, currently hyper focused on LLM agent chains and related technology, flips knives for fun (balisong).