Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m1guelpf/laravel-multiformat
Multiformat Endpoints in Laravel
https://github.com/m1guelpf/laravel-multiformat
endpoint laravel laravel-package multiformats package
Last synced: 2 months ago
JSON representation
Multiformat Endpoints in Laravel
- Host: GitHub
- URL: https://github.com/m1guelpf/laravel-multiformat
- Owner: m1guelpf
- License: mit
- Created: 2018-02-17T15:44:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-22T21:19:47.000Z (about 4 years ago)
- Last Synced: 2024-10-25T05:58:18.205Z (2 months ago)
- Topics: endpoint, laravel, laravel-package, multiformats, package
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 39
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Multiformat Endpoints in Laravel
[![Latest Version on Packagist](https://img.shields.io/packagist/v/m1guelpf/laravel-multiformat.svg?style=flat-square)](https://packagist.org/packages/m1guelpf/laravel-multiformat)
[![Total Downloads](https://img.shields.io/packagist/dt/m1guelpf/laravel-multiformat.svg?style=flat-square)](https://packagist.org/packages/m1guelpf/laravel-multiformat)## Installation
You can install the package via composer:
```bash
composer require m1guelpf/laravel-multiformat
```## Usage
``` php
multiformat();/**
* Use `Request::match()` to return the right response for the requested format.
*
* Supports closures to avoid doing unnecessary work, and returns 404 if the
* requested format is not supported.
*
* Will also take into account the `Accept` header if no extension is provided.
*/
class PodcastsController
{
public function show($id)
{
$podcast = Podcast::findOrFail($id);
return request()->match([
'html' => view('podcasts.show', [
'podcast' => $podcast,
'episodes' => $podcast->recentEpisodes(5),
]),
'json' => $podcast,
'xml' => function () use ($podcast) {
return response($podcast->toXml(), 200, ['Content-Type' => 'text/xml']);
}
]);
}
}
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Adam Wathan](https://github.com/adamwathan) for the [original gist](https://gist.github.com/adamwathan/984914b2eee8e4d79a06f7045e4ce999)
- [Miguel Piedrafita](https://github.com/m1guelpf)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.