phenax / plasmajs

An isomorphic nodeJS framework based on react
Apache License 2.0
134 stars 12 forks source link

Resources for api routes - An alternative to APIRouter. #7

Open phenax opened 6 years ago

phenax commented 6 years ago

Branch: dev_resources_api

An alternative to APIRouter.

API Possibilities

  1. Simple (Most consistent with the rest of the api)
    <Resource name='posts'>
    <Action path='/' action={listPost} />
    <Action path='/add' method='POST' action={createPost} />
    </Resource>

OR

  1. Method names as actions
    // Class declaration
    class ControllerClass extends BaseController {
    listPost() { /* ... */ }
    createPost() { /* ... */ }
    }
    // Usage
    <Resource name='posts' controller={ControllerClass}>
    <Action path='/' action='listPost' />
    <Action path='/add' method='POST' action='createPost' />
    </Resource>

OR

  1. Declaring stuff with decorators

    // Class declaration
    @resource('post')
    class ControllerClass extends BaseController {
    
    @action('/')
    listPost() { /* ... */ }
    
    @action('/add', 'POST')
    createPost() { /* ... */ }
    }
    // Usage
    <Resource controller={ControllerClass} />