Menu

1 / 6

HTTP QUERY in Laravel: The Cart Reads We Moved to POST

DEV Community: laravel·Ivan Mykhavko·6 days ago
#UqKmai3M
#devtolaravel#devto#dev#query#route
Long article (2023 words) — no AI summary yet.
Reading 0:00
15s threshold

In early 2024 I moved four cart endpoints from GET to POST. None of them writes anything. They read the cart, count totals, check if checkout is possible and load delivery schedules. The URL just got too long, and POST was the only verb that takes a body.

This year HTTP got a new method for exactly this case, and Laravel already supports it. So I went back to that cart to see if it is time to undo the hack.

The Cart That Reads With POST

In a project I work on, the frontend asks the backend about the items a customer selected in the cart. The API has no sessions, so the backend doesn't remember that selection: every read carries the list of item uuids, and a big cart sends hundreds of them:

final class CartItemIndexRequest extends FormRequest { public function rules ( ) : array { return [ 'filter' => [ 'array' , 'min:1' , 'max:500' ] , 'filter.item_uuid.*' => [ 'required' , 'string' , 'max:100' ] , ] ; } }

Enter fullscreen mode

Exit fullscreen mode

In February 2024 the reads were plain GET routes, and…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.