# adonis4-api

> Restful api for AdonisJs 4 with validation

Latest version **1.0.5** (published 2018-02-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install adonis4-api
pnpm add adonis4-api
yarn add adonis4-api
bun add adonis4-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-02-07 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Christian Cannata |
| Maintainers | christiancannata |

## Links

- npm: https://www.npmjs.com/package/adonis4-api
- Repository: https://github.com/christiancannata/adonis-rest
- Homepage: https://github.com/christiancannata/adonis-rest#readme
- Issues: https://github.com/christiancannata/adonis-rest/issues
- npm.io page: https://npm.io/package/adonis4-api

## Dependencies (2)

- [i](https://npm.io/package/i.md) ^0.3.6
- [@adonisjs/validator](https://npm.io/package/@adonisjs/validator.md) ^5.0.0

## Recent versions

- 1.0.5 (latest) — 2018-02-07
- 1.0.4 — 2018-02-07
- 1.0.3 — 2018-02-01
- 1.0.2 — 2018-02-01
- 1.0.1 — 2018-02-01
- 1.0.0 — 2018-02-01
- 1.2.0 — 2018-02-01

## README

# adonis4-api
Restful api for AdonisJs 4

## Install

1. `npm install --save adonis4-api`


## Prepare
Tips: Please be sure that you have some models in `/app/Models/`.  Use `adonis make:model News` to create a News model if not.

> /app/Http/routes.js
``` javascript
Route.put('/api/:resource', 'RestController.update') //optional
Route.resource('/api/:resource', 'RestController')
```

> Create `/app/Http/Controllers/RestController.js`

``` javascript
'use strict'

const BaseRestController = require('adonis4-api')

class RestController  extends BaseRestController{

}

module.exports = RestController
```

That's all. Now you get all apis of your models.

## Documentations

> Base uri: `http://localhost:3333/api`


| METHOD | URL | DESCRIPTION |
| --- | --- | --- |
| GET | /news | Get all news |
| POST | /news | Create a news |
| PUT/PATCH | /news/:id | Update a news |
| DELETE | /news/:id | Delete a news |


### GET `/news`
Get all news

#### Url Query String

page query filter per_page perPage limit offset skip where expand fields groupBy orderBy pagination

| NAME | SAMPLE VALUE | DESCRIPTION |
| --- | --- | --- |
| pagination | 1 | Return data with pagination info if set any value, otherwise return the flat array. But you can retrive pagination info from reponse `headers` |
| query | {"user_id": 1} | Also you can use `filter` or `where` |
| page | 1 | Current Page |
| perPage | 10 | Also you can use `limit` |
| offset | 10 | Also you can use `skip` |
| fields | id,title,created_at | Fields for `select` |
| orderBy | id | Use `-id` for `desc` |

### Formats of `query`
- `query={"created_at": "2017-07-07"}`
- `query={"created_at": [">", "2017-07-07"]}` or `<`,`<>` etc
- `query={"created_at": ["between", ["2017-07-01", "2017-07-31"]]}` or `notBetween`
- `query={"user_id": ["in", [1,2,3] ]}` or `notIn`
- `query={"user_id": ["raw", 'user_id IS NULL' ]}`


## Any Problem?
Just tell me in `Issues`

---
_Source: https://npm.io/package/adonis4-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
