Skip to content

Commit

Permalink
add silent response documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dropelikeit committed Oct 25, 2023
1 parent 96e94d7 commit 61a749e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion UPGRADE-5.0.md
Expand Up @@ -14,4 +14,4 @@ Since Laravel 9+ requires PHP 8.1, this PHP version is also required in this lib

### Patches

- The cache directory now points to the "/storage/cache" directory.
- The cache directory now points to the "/storage/cache" directory.
27 changes: 27 additions & 0 deletions docs/response-factory.md
Expand Up @@ -58,4 +58,31 @@ You do not always want to hand over a status code of 200 to the frontend. You ca
return $this->responseFactory->create($myDataObjectWithSerializerAnnotations);
}
}
```

## Using quiet response

Q: What is a silent response?
A: Quite simply, it is a normal Laravel response that contains the 204 status code. The 204 HTTP code does not represent any content, but it was successful.

You dont't need to add the 204 status code yourself, when you call the `createQuietResponse` method, it will be set automatically.

```php
<?php
declare(strict_types=1);

namespace App\Http\Controller;

use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
use Symfony\Component\HttpFoundation\JsonResponse;

final class ExampleController extends Controller
{
public function __construct(private ResponseFactory $responseFactory) {}

public function myAction(): JsonResponse
{
return $this->responseFactory->createQuietResponse();
}
}
```

0 comments on commit 61a749e

Please sign in to comment.