github.com/Zewo/TodoBackend

A Zewo implementation of Todo Backend (HTTPServer, PostgreSQL)


License
MIT

Documentation

Todo Backend

Swift 3.0 Zewo Platforms Mac - Linux License MIT Slack Status

This repository contains an implementation of Todo Backend created using Zewo components.

The Todo-Backend project helps showcase and compare different language and framework combinations for building web services. This website defines a simple web API in the form of a todo list and users can create their own identical APIs using various tech stacks. This website then provides a spec runner to verify that the user implementation is identical to the base implementation.

Architecture

The application is split up into three components: Models, Resources, and Storage.

Models

The Models directory contains the bare minimum for the Todo model and avoids giving it state/optionality by abstracting its "entity" behavior (id, url) in an Entity wrapper struct. The (fairly concise) boilerplate for serializing and instantiating the structs from and to StructuredData, which is then transparently converted to the correct data type for the API (in this case, JSON) by the resource.

Resources

The resources directory contains a single resource which defines all of the routes. Since most of the hard work (serializing our models to and from JSON) is done by the Resource module, the rest of the code is just glue that interacts with the data store.

Storage

For Storage, we define a TodoStore protocol which defines the necessary methods for interacting with a data store (fetch, insert, update, remove). A simple in-memory implementation of the protocol is included which just uses a dictionary for storage.

Thanks to this architecture, our application's code is simple to understand, boilerplate-free, and highly maintainable. While this is by no means a perfect architecture, it can be a good example to follow for your own application.

Setup

Setting up the environment

You can follow the setup instructions for Zewo in the main readme. In short, just install the 05-09 Swift development snapshot.

Running the project locally

Simply clone this repository (git clone https://github.com/Zewo/TodoBackend.git) and run swift build. Once the build process finishes, an executable for the application should pop up at .build/debug/TodoBackend.

Deploying the project with Docker

To begin, clone the repository (git clone https://github.com/Zewo/TodoBackend.git) and install Docker.

There is a basic Dockerfile in the root of the repository that installs Swift, builds the application, and runs it. Before you can use it, however, you need to set the API_ROOT environmental variable to the full url at which it will be deployed (for example, https://myapi.com/).

Once you have the Dockerfile configured, build the docker image (docker build -t zewo/todobackend .). With the image built, run it using the docker run family of commands. For example, docker run -itd -p 0.0.0.0:80:8080 zewo/todobackend will start a container running the Todo Backend application in the background, and map the containers 8080 port to the machine's 80 (default http) port.

Support

If you need any help you can join our Slack and go to the #help channel. Or you can create a Github issue in our main repository. When stating your issue be sure to add enough details, specify what module is causing the problem and reproduction steps.

Community

Slack

The entire Zewo code base is licensed under MIT. By contributing to Zewo you are contributing to an open and engaged community of brilliant Swift programmers. Join us on Slack to get to know us!

License

This project is released under the MIT license. See LICENSE for details.