Skip to content

swiftlang/swift-server-todos-tutorial

SwiftServerTodos – a Swift server tutorial

A tutorial for building a server-side TODO management application using Swift.

Overview

SwiftServerTodos demonstrates building an HTTP service in Swift. This repository contains a tutorial and code samples for creating a backend service using Vapor, OpenAPI, and PostgreSQL.

Contents:

  • SwiftServerTodos.docc: DocC tutorial with step-by-step instructions.
  • <root directory>: Starter code for tutorial exercises.
  • Completed: Completed implementation for reference.

Tutorial topics

The tutorial covers these Swift server development topics:

  • HTTP service implementation with Vapor.
  • Code generation from an OpenAPI document.
  • Database persistence using the Fluent ORM and PostgreSQL.
  • Service configuration and lifecycle management.

Requirements

Getting started

Clone the repository

git clone https://github.com/swiftlang/swift-server-todos-tutorial
cd SwiftServerTodos

Follow the tutorial

To preview the tutorial locally:

xcrun docc preview -p 8090

The tutorial is available at http://localhost:8090/tutorials/getting-started-swift-server.

Working with the tutorial

  1. Open the DocC tutorial to read concepts and implementation details.
  2. Use the root directory as the starting package for the tutorial.
  3. Reference the package in the Completed/ directory for the final implementation.
  4. Modify Package.swift and files in Sources/ as you progress through the tutorial steps.

Architecture

The application uses a three-tier architecture:

  • HTTP Layer: Vapor web framework for HTTP request handling.
  • Business Logic: OpenAPI-generated handlers for request processing.
  • Data Layer: Fluent ORM for database operations with PostgreSQL.

Dependencies

Core frameworks

Additional libraries

API documentation

The service implements a RESTful API for TODO management:

  • GET /todos – Retrieve all todos.
  • POST /todos – Create a new todo.
  • GET /todos/{id} – Retrieve a specific todo.
  • PUT /todos/{id} – Update a todo.
  • DELETE /todos/{id} – Delete a todo.

The complete API specification is available in Sources/SwiftServerTodos/openapi.yaml.

Related resources

Alternative frameworks

Example projects

Contributing

Build tutorial

Verify the tutorial builds without errors or warnings using the command:

xcrun docc convert --warnings-as-errors --analyze

Preview tutorial

Preview the tutorial content. Run the following command, then review your updates at http://localhost:8090/tutorials/getting-started-swift-server:

xcrun docc preview -p 8090

About

A tutorial for building a server-side TODO management application using Swift.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •