I have a bunch of routes and they all start with /api/2.01
.
How can I add it once so it applies to all routes. Slim Framework Base URL asks the same question, but I believe provides an outdated answer.
PS. If instead of asking a new question, should I have instead somehow tagged the post which I believe is dated to be reviewed or something?
$app = new \Slim\Slim();
$app->post('/api/2.01/books', function () {
//Create books
});
$app->get('/api/2.01/books', function () {
//getbook
});
$app->get('/api/2.01/books/{id}', function () {
//Get book
});
$app->delete('/api/2.01/books/{id}', function () {
//Create book
});
If you are using Slim v2.0, you can do somtehing like:
// API group
$app->group('/api', function () use ($app) {
// Library group
$app->group('/library', function () use ($app) {
// Get book with ID
$app->get('/books/:id', function ($id) {
});
// Update book with ID
$app->put('/books/:id', function ($id) {
});
// Delete book with ID
$app->delete('/books/:id', function ($id) {
});
});
as specified in the docs: http://docs.slimframework.com/routing/groups/