Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rest Bundle Laravel Package

dmp/rest-bundle

View on GitHub
Deep Wiki
Context7

REST Bundle

This bundle provides convenient functionality to write simple and powerful JSON-based RPC controllers

How to use:

Add bundle DMP\RestBundle\RestBundle to your kernel.

Write controllers in a style:

use DMP\RestBundle\Annotation as Rest;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;

class TestController
{

    #[Route("/api/test", methods: ["POST"])]
    #[Rest\Serializable(statusCode: 201)]
    public function request(#[MapRequestPayload] RequestDTO $request): ResponseDTO
    {
        ...
    }
}

where RequestDTO and ResponseDTO are Data Transfer Objects that should define Serialization and Validation rules for the fields

All routes should start with '/api/' (TODO: remove this hard-coded requirement)

Consult tests/Fixtures/ directory for an overview of how to define Rest Controllers

Request Data Mapping

Use Symfony's native attributes for mapping request data to DTOs:

  • #[MapRequestPayload] for JSON request body.
  • #[MapQueryString] for query parameters.

The bundle's ExceptionListener will automatically catch validation errors from these attributes and format them into a consistent JSON response.

Exceptions

If the controller throws an exception, it will be converted into a response in the form

{
  "errors": [
    {
      "message": "Exception message"
    }
  ]
}

Validation error responses are different:

{
  "errors": [
    {
      "message": "Field value should be a valid email address.",
      "field": "email",
      "parameters": {}
    },
    {
      "message": "Field value should not be blank.",
      "field": "password"
    }
  ]
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast