Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.