Skip to content

controller

Pierre Besson edited this page Aug 12, 2014 · 4 revisions

Server side

RESTFULL API

Controller, ROUTE, Structure

In order to expose an API, you have to map url to route wich trigger specific actions. We assume that our application is RESTFULL. It means a route is able to CREATE, RETRIEVE, UPDATE, DELETE an object: CRUD

  • A controller should match a simple route with the following actions
  • GET => Should load an object (somtimes with a param)
  • POST => Should create an object or be use in order to load.
  • PUT => Should update an object.
  • DELETE => Delete an object (often take an id paramater)
  • In order to have a controller for a contact: (CRUD)

POST

http://domainName/contact** => CREATE a contact
POST one element

GET

http://domainName/contact/1 => RETRIEVE all contacts
GET one element

GET

http://domainName/contact/1 => RETRIEVE a contact with an id 1

GET action

PUT :

http://domainName/contact/1 => UPDATE a contact with an id 1
PUT action

DELETE

http://domainName/contact/1 => DELETE a contact with an id 1
DELETE action

TOOLS

DevTools in chrome

In order to easily test web apis, you can use two tools:

The network tab of the chrome dev tools (it means you have to write JS code in order to perform ajax requests for other request than GET and visualize them).

Chrome Network Devtools

The POSTMAN chrome extension.

POSTMAN Extension

next

Clone this wiki locally