Skip to main content
highlighted:

Create a resource API

Resources is content CRUD, one resorce have all routes need for get, create, update and delete your contents (model)

Routes generated by resources are extendable. Ex: you can set new routes for things like get content count

Tip: Use we routes command to list all routes with suport to filters, see options แบith we routes -h

1- Create one app

Tip:

yo wejs:app

And follow all instructions for set database and first user (optional)

2- Make the post resource

Lets see how to make a resource with generator-wejs:

This will generate the controller, model and resource routes.

Inside one project or plugin tip:

yo wejs:resource post title:string:allowNull=false teaser:text body:text published:boolean

yo wejs:resource post generate the post model and title:string:allowNull=false teaser:text body:text published:boolean will be model attributes

And done!

TIP: Use we routes command to list and filter all routes in your project.

By default this will make:

## API:
post /post # create
get /post # list, find
get /post/:postId # find one
put /post/:postId # update one
delete /post/:postId # delete one

And if we-plugin-view is installed will generate:

## API:
post /post # create
get /post # list, find
get /post/:postId # find one
put /post/:postId # update one
delete /post/:postId # delete one
## pages:
get /post/create
get /post/:postId/edit
post /post/:postId/edit
get /post/:postId/delete
post /post/:postId/delete

3- Run project in development mode

we run

4- Make the Swagger documentation

In project folder tip:

yo wejs:doc

See routes documentation page for more information about routes and resources



afterContent:
Widget: Comments 13:

Comments