1.0.5 • Published 6 years ago

adonis4-api v1.0.5

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

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

Route.put('/api/:resource', 'RestController.update') //optional
Route.resource('/api/:resource', 'RestController')

Create /app/Http/Controllers/RestController.js

'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

METHODURLDESCRIPTION
GET/newsGet all news
POST/newsCreate a news
PUT/PATCH/news/:idUpdate a news
DELETE/news/:idDelete 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

NAMESAMPLE VALUEDESCRIPTION
pagination1Return 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
page1Current Page
perPage10Also you can use limit
offset10Also you can use skip
fieldsid,title,created_atFields for select
orderByidUse -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

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.2.0

6 years ago