Skip to content

Simplified Todo example for using MongoKitten 4 with Vapor 3

Notifications You must be signed in to change notification settings

sthapaun/vapor3-mongo-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Template

Documentation Team Chat MIT License Continuous Integration Swift 4.1

Getting started

Open the project folder in terminal and sync up.

swift package update                   # update dependencies
swift package generate-xcodeproj       # regenerate Xcode project
open *.xcodeproj                       # open Xcode

Before running the project, make sure MongoDB is installed on your machine and is running.

Option 1: Docker

Assuming you have Docker for Mac installed and running, create a new MongoDB container with:

docker run --name example-mongo -p 27017:27017 mongo:latest

Or if you've done this once, start the existing container:

docker start example-mongo

Option 2: Installing MongoDB via Homebrew

brew update
brew install mongodb

Next, create the db folder for MongoDB to store the databases and check the permissions for the db folder:

mkdir -p /data/db
sudo chown -R `id -un` /data/db

Launch the MongoDB server:

mongod

Now, run the project on xcode.

Testing the project

Using Postman

The Postman (API Development Environment) is a neat tool for setting up and performing HTTP requests repeatably.

Creating a Todo

Create a POST request to the following URL:

http://localhost:8080/todos

And set the following two keys and values in the body:

key value
id 1
title Hi!

Note: If there are no key and values in the body of the post request, you will see the following error:

[ ERROR ] Abort.415: No 'Content-Type' header is present. ContentContainer.swift:320)

Getting the Todo list

Create a GET request to the following URL:

http://localhost:8080/todos

You should see the created Todo from the POST request.

About

Simplified Todo example for using MongoKitten 4 with Vapor 3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%