Vapor project with MongoDB
This project uses the Swift Web framework Vapor with MongoDB to create a generic API for consuming users and objects of any type with any data without having to update the API code or the DB schema.
In order to connect to MongoDB you must add a mongo.json file inside of the folder Config/secrets.
The mongo.json file must contain the following structure:
{
"user": "",
"password": "",
"database": "local",
"port": "27017",
"host": ""
}
The user is used for authentication and authorization.
{
"id" : "581f3d7d1940cb25cb1b1f2d",
"username" : "gabriel",
"password" : "12345678",
"data" : {
...
},
"access_token" : "...",
}
The object is used to manage generic objects.
{
"id" : "581f3d7d1940cb25cb1b1f2d",
"type" : "object type, used for filtering",
"data" : {
...
}
}
The data property can also be an array.
This project also contain posts which is the example from Vapor example.
The path for registration is /api/users/register and all the neccessary attributes for user like username and password should be setted.
Every path of the app needs the Bearer access_token setted in Authorization header of the request in order to access the data or perform an action.
The access_token is setted by the path /api/users/token where you should provide the username and password of the user. In a future commit the access_token will also be returned in the registration process.
Vapor is the most used web framework for Swift. It provides a beautifully expressive and easy to use foundation for your next website, API, or cloud project.
Website
Visit the Vapor web framework’s documentation for instructions on how to use this package.
Join the welcoming community of fellow Vapor developers in slack.
Vapor package has been tested on macOS and Ubuntu.
MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License.