swift-on-server-rest-api-vapor-mongodb
Swift is a general-purpose programming language built using a modern approach to safety & performance that make it specifically suitable for Server applications. Vapor is a web framework for Swift, allowing you to write backends, web apps APIs and HTTP servers in Swift
This Project domonstrate the latest Swift on Server to create RESTFul API's connected via Database: MongoDB NoSql
Swift 5.5+ - support async/await structured concurrency pattern
( https://developer.apple.com/videos/play/wwdc2021/10132 )
Requirements: mac OS Monterey (v 12), Xcode 13.0
Clone the repo
Open the folder "hello" in Xcode 13 or later
Package dependencies will be installed by Xcode
MongoDB instance required at cloud or localhost: "mongodb://localhost:27017/vapor"
Run the project -> http Server will be available at: Server starting on http://127.0.0.1:8080
From Postman following APIs are accessible:
Create User : [ POST ] http://localhost:8080/users
Get All Users : [ GET ] http://localhost:8080/users
JWT Authentication Middleware:
Login : [ POST ] http://localhost:8080/login
Response: { "token": "eyJhbG..." }
Header: [ 'Authorization': Bearer eyJhbGciO... ]
Get A User: [ GET ] http://localhost:8080/users/id
Deployments options available via Docker, Systemd, Supervisor for Linux / Unix based OS
Vapor Framework
https://vapor.codes/
If you are interested to know more about the Future of SwiftOnServer, please check my recent post:
https://www.linkedin.com/posts/muhammad-furqan-121b691a_swiftonserver-swift-server-activity-6954367874148749312-JBrD?utm_source=linkedin_share&utm_medium=member_desktop_web
Furqan
(Software Developer / Solution Architect)