Skip to content

Instantly share code, notes, and snippets.

@paulofaria
Last active March 8, 2016 05:35
Show Gist options
  • Save paulofaria/02385cee2a4ec773964d to your computer and use it in GitHub Desktop.
Save paulofaria/02385cee2a4ec773964d to your computer and use it in GitHub Desktop.
let todoResources = Resource(middleware: recovery, contentNegotiaton) { todo in
todo.index { _ in
let todos = try app.getAllTodos()
return Response(content: ["todos": todos.content])
}
todo.create(mappingTo: Todo.self) { request, todo in
let todo = try app.createTodo(todo)
return Response(content: todo)
}
todo.show { _, id in
let todo = try app.getTodo(id: id)
return Response(content: todo)
}
todo.update { request, id, content in
let todo = try app.updateTodo(
id: id,
title: try? content.get("title"),
done: try? content.get("done")
)
return Response(content: todo)
}
todo.destroy { _, id in
try app.removeTodo(id: id)
return Response(status: .NoContent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment