Learn VAPOR with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Vapor Simple REST API
import Vapor
struct Todo: Content {
var id: UUID?
var title: String
var completed: Bool
}
var todos: [Todo] = []
func routes(_ app: Application) throws {
app.get("/todos") { req -> [Todo] in
return todos
}
app.post("/todos") { req -> Todo in
let todo = try req.content.decode(Todo.self)
todos.append(todo)
return todo
}
}
let app = Application()
defer { app.shutdown() }
try routes(app)
try app.run()
Demonstrates a simple Vapor application with routes for listing and creating Todo items.