Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/fumeapp/metapi

Laravel API helpers including benchmarking and interactive browsing
https://github.com/fumeapp/metapi

api json jsonapi jsonp laravel laravel-package pretty-print

Last synced: 1 day ago
JSON representation

Laravel API helpers including benchmarking and interactive browsing

Awesome Lists containing this project

README

        



> Own your endpoint

metapi's main purpose is to help make sure your endpoint responses are consistent. By using the built in helper functions like `->option()...->verify`, `->render()`, `->success()` and `->error()` they will all share the same consistent standardized output reflecting the options available, parameters provided, and results.

[![Latest Stable Version](https://poser.pugx.org/acidjazz/metapi/version.png)](https://packagist.org/packages/acidjazz/metapi)
[![Total Downloads](https://poser.pugx.org/acidjazz/metapi/d/total.png)](https://packagist.org/packages/acidjazz/metapi)
[![codecov](https://codecov.io/gh/acidjazz/metapi/branch/master/graph/badge.svg)](https://codecov.io/gh/acidjazz/metapi)

> Dracula dark theme with laravel-debugbar

## Features
* Endpoint benchmarking
* Laravel Validation wrapper that reflects requirements
* Support for JSON and JSONP
* Interactive tree browsing with search thanks to [jsoneditor](https://github.com/josdejong/jsoneditor)
* Dracula Dark theme support to pair with [laravel-debugbar](https://github.com/barryvdh/laravel-debugbar)

## Installation

Install metapi with [composer](https://getcomposer.org/doc/00-intro.md):
```bash
composer require acidjazz/metapi
```

Add the trait
> (`app/Http/Controllers/Controller.php` is recommended)
```php
option('approved', 'nullable|boolean');
->option('type', 'nullable|in:this,that');
->verify();
...
$this->render($results);
```

`GET /endpoint?approved=1`

```json
{
"benchmark": 0.011060953140258789,
"query": {
"defaults": [],
"options": {
"approved": "nullable|boolean",
"type": "nullable|in:this,that"
},
"params": {
"approved": "1"
},
"combined": {
"approved": "1"
}
},
"data": [
{
```

`GET /endpoint?callback=bob`

```js
bob({
"benchmark": 0.011017084121704102,
"query": {
"defaults": [],
"options": {
"approved": "nullable|boolean",
"type": "nullable|in:this,that"
},
"params": [],
"combined": []
},
"data": [
{
```

**Add [custom attributes](https://laravel.com/docs/9.x/validation#specifying-custom-attribute-values) to validation.**

```php
public function send(Request $request)
{
$this->option('contact.email', 'required|email', [], 'Email Address')
->option('contact.name', 'required|string', [], 'Firstname')
->option('contact.surname', 'required|string', [], 'Lastname')
->verify();
...
$this->render($results);
}
```

`POST /send`

```json
{
"status": "error",
"errors": [
{
"status": 400,
"message": "contact.email",
"detail": "Email Address is a required field."
},
{
"status": 400,
"message": "contact.name",
"detail": "Firstname is a required field."
},
{
"status": 400,
"message": "contact.surname",
"detail": "Lastname is a required field."
}
]
}
```