https://github.com/membrane-php/membrane-psr15
https://github.com/membrane-php/membrane-psr15
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/membrane-php/membrane-psr15
- Owner: membrane-php
- License: other
- Created: 2022-12-16T10:34:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-07T08:52:26.000Z (almost 3 years ago)
- Last Synced: 2025-01-20T06:37:26.737Z (about 1 year ago)
- Language: PHP
- Size: 5.57 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Membrane-Psr15
Integrates [Membrane-core](https://github.com/membrane-php/membrane-core) with any project implementing Psr7.
## About
Middleware that validates the raw user input from incoming HTTP requests against your OpenAPI spec.
Adds a `Membrane\Result\Result` onto your `ContainerInterface`.
The Result object contains the cleaned up data and additional details in the case of invalid requests.
## Setup
### Installation
Require the `membrane/psr15` package in your composer.json and update your dependencies:
```text
composer require membrane/laravel
```
## Usage
### Requests
The `\Membrane\Psr15\Middleware\RequestValidation` middleware will validate or invalidate incoming requests and let you decide how to react.
You can precede it with your own custom middleware or precede it with one of the following built-in options:
### Responses
Any response middleware MUST follow the `RequestValidation` middleware as it requires the `result` object being added to
your container.
These middlewares will check whether the request has passed or failed validation.
Invalid requests will return an appropriate response detailing the reasons the request was invalid.
#### Flat Json
`\Membrane\Psr15\Middleware\ResponseJsonFlat`
**Example Output**
```text
{
"errors":{
"pet->id":["must be an integer"],
"pet":["name is a required field"]
},
"title":"Request payload failed validation",
"type":"about:blank",
"status":400
}
```
#### Nested Json
`\Membrane\Psr15\Middleware\ResponseJsonNested`
**Example Output**
```text
{
"errors":{
"errors":[],
"fields":{
"pet":{
"errors":[
"name is a required field"
],
"fields":{
"id":{
"errors":[
"must be an integer"
],
"fields":[]
}
}
}
}
},
"title":"Request payload failed validation",
"type":"about:blank",
"status":400
}
```