Simple REST API - Vapor Typing CST Test
Loading…
Simple REST API — Vapor Code
Demonstrates a simple Vapor application with routes for listing and creating Todo items.
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()Vapor Language Guide
Vapor is a server-side Swift web framework designed for building fast, safe, and scalable web applications and APIs, fully leveraging Swift’s type safety and performance.
Primary Use Cases
- ▸Server-side Swift web applications
- ▸RESTful APIs and microservices
- ▸Backend for iOS/macOS apps
- ▸Real-time applications using WebSockets
- ▸Cloud-native services deployed on Vapor Cloud or Docker
Notable Features
- ▸Swift NIO-powered asynchronous networking
- ▸MVC architecture for structured development
- ▸Leaf templating engine for server-side rendering
- ▸Fluent ORM for database abstraction
- ▸Middleware support for security, logging, and routing
Origin & Creator
Created by Tanner Nelson in 2016, maintained by the Vapor community.
Industrial Note
Vapor is popular for Swift developers building server-side applications, REST APIs, and real-time services, especially in ecosystems that favor Swift, like Apple platforms.