Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Writing the Todo API

All that is left on the server side of our todo application is to write an API to access our todo resources from the client side code we’ll write in the next chapter. Let’s start by adding a file to handle all the requests we expect for our API:

Example: (source: app.4/src/controllers/todos_controller.coffee)


# This 'controller' will handle the server requests
# for the Todo resource

# Get a list of the todos:
app.get '/api/todos', (req, res) ->
  res.json [{}]

# Create a new todo:
app.post '/api/todos', (req, res) ->
  res.json {}

# Get a specific todo:
app.get '/api/todos/:id', (req, res) ->
  res.json {}

# Update a specific todo:
app.put "/api/todos/:id", (req, res) ->
  res.json {}

# Destroy a specific todo:
app.delete '/api/todos/:id', (req, res) ->
  res.json {}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial