Tanmay Mishu

Parsing JSON Request Body in Go Fiber

When the default body parser of the Fiber framework fails to parse a JSON request body, it returns an error message which is not very human-readable and client-side-friendly. Say for example, you expect a json field named post_id in the request body of your API endpoint and you expect its value to be an integer, but nothing is stopping the API-consumer from sending an unacceptable type of value in the post_id field:

Undocumented Laravel: Pipelines

Have you ever wanted to perform a series of tasks/operations on an object (or any type of data) and had to manually build up the process yourself? Did you know that you could easily handle such situations with a pattern that is built into the Laravel framework, called “Pipelines”? If you’re familiar with the concept of middleware, you already know that when a request enters the application, the request is passed through a series of middleware, traveling from the current middleware to the next.

Undocumented Laravel: Macros

Often in your controller actions or route closures, you may have come across situations where you want to send a JSON response with an HTTP status, especially when you’re working with REST APIs: response()->json(['message' => 'Unauthorized'], 403); Suddenly you realize that you’re using the same snippet across your application over and over again. Wouldn’t it be nice if you could just write something like this: response()->forbid(); …which actually takes care of building up that JSON response?

The Anatomy of Laravel's tap() Function

If there is one thing I really like about the Laravel PHP Framework, it would be its level of code sophistication, whether it is in something as complex as the ORM or even in something as simple as a helper function. The latter is what this article is about. Laravel has a Ruby-inspired, higher-order function called tap(). In a nutshell, the tap helper function takes a value and a callback; passes the value to the callback and returns the value.