I am trying to wrap my head around how to create a RESTful API with SLIM. I understand REST and I have a good understanding of slim but what I can understand is how to render the correct view templates.
This is a typical REST API
$app->get('/wines', 'getWines');
$app->get('/wines/:id', 'getWine');
$app->post('/wines', 'addWine');
$app->put('/wines/:id', 'updateWine');
$app->delete('/wines/:id', 'deleteWine');
Now what I don't understand is if all the routes have the same URL how can you render the correct view template. The first GET request displays all the wines. The next GET displays only the wine with the specified id. Now this is where my understanding falters. When I want to add a wine I write a route that reacts differently to either a GET or POST request.
$app->map('/wines', function() {
echo "I respond to multiple HTTP methods!";
})->via('GET', 'POST');
So for the get request I want show a form so I can enter a new wine but as the URL is the same as getting all the wines and they are both GET requests how can I render the correct template.
I hope this makes sense.
Thanks