Hojzerice
Hojzerice

Reputation: 45

NodeJS Restify Routes grouping

coming from Laravel background I was used to grouping routes together like this

$API_V1 = [
    'prefix' => 'v1',
    'as' => 'api.',
    'namespace' => 'App\Http\Controllers'
];
Route::group($API_V1, function () {
    Route::get('/stations', 'RadioController@listStations');
    Route::get('/stations/country', 'RadioController@listStationsByCountry');
    Route::get('/stations/genres', 'RadioController@listStationsGenres');

});

$API_V1_RESTRICTED = [
    'prefix' => 'v1',
    'as' => 'api.',
    'namespace' => 'App\Http\Controllers',
    'middleware' => 'auth:api'
];

//Restricted Acsess
Route::group($API_V1_RESTRICTED, function () {
    //Route::apiResource('/radio', 'RadioController');
    Route::post('/stations', 'RadioController@addStation');
    Route::put('/stations/{id}', 'RadioController@updateStation');
    Route::delete('/stations/{id}', 'RadioController@deleteStation');
    Route::get('/user', 'RadioController@CheckUser');

});

//Authentication endpoints
$API_V1_REGISTER = [
    'prefix' => 'v1',
    'as' => 'api.',
    'namespace' => 'App\Http\Controllers\Auth'
];

Route::group($API_V1_REGISTER, function () {

    Route::post('register', 'RegisterController@register');
    Route::post('login', 'LoginController@login');
    Route::get('logout', 'LoginController@logout');

});

does Restify offer something similar, (grouping was realy usefull for API versioning and also for easly make some routes restricted) because unfortionatly I have to use NodeJS and restify for this particular project, and I realy got used to some Laravel features :)

Thanks for Anwsering and Best Regards

Upvotes: 1

Views: 122

Answers (0)

Related Questions