0 Best Reply Awards

  • Member Since 10 Months Ago
  • 33 Lessons Completed
  • 0 Favorites

15th November, 2017

dynait left a reply on API Version Control In Header • 10 months ago

Hello guys,

I have started to build an API and the versioning is something that i have to take care of it form the initial stage. The API must be RESTful and for that reason the api version is has been included in the request headers. As tjoskar proposed in a previous old post you can create a middleware which will be responsible to handle the request and check the headers for the api version. The problem here is how we can pass the api version to the appropriate route path keeping the routes autonomous.

What i have already done in my implementation which is working properly, i replaced the request path with a new one including the api version and then i copied the request. Then, the handle method of my middleware returns the new duplicated request which is updated with the new uri path.


//a copy of the request $dupRequest = $request->duplicate();

return $next($dupRequest);

Any comments or suggestions?

Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.