A declarative server-side framework for Swift is a new project that aims to make it easier for developers to write code in Swift.

The server-side swift tutorial is a unique framework that allows you to write server-side Swift code.

14 September 2021 3 minutes to read

The first truly declarative server-side framework for Swift

The-first-truly-declarative-server-side-framework-for-Swift

1631625370_920_The-first-truly-declarative-server-side-framework-for-Swift

Corvus is the first server-side framework for Swift that is fully declarative. It has a declarative, composable syntax that makes it simple to set up and use APIs. It’s strongly influenced by Vapor’s previous work.

An example of a full-featured API that handles Bank Accounts and Transactions for specific users is shown below. It also demonstrates how simple it is to build up authentication and authorisation rules for particular routes.

 

User(“users”)

Login(“login”)

AccountsEndpoint() TransactionsEndpoint() BearerAuthGroup “>

allow xpenseApi to be equal to Api (“api”) BearerAuthGroup User(“users”) Login(“login”) AccountsEndpoint() TransactionsEndpoint()

Because Corvus is modular, it’s simple to utilize a collection of components as a single component:

 

allow parameter to equal parameter ()

content: var Group of Endpoints (“accounts”) ReadAll().auth(.$user) Create().auth(.$user) Create().auth(.$user) Create().auth(.$user) Create().auth(.$user) Create()

Delete(parameter.id).auth(.$user) Group(parameter.id) ReadOne(parameter.id).auth(.$user) Update(parameter.id).auth(.$user) Delete(parameter.id).auth(.$user)

AccountsEndpoint is the last class in the AccountsEndpoint package. if parameter = parameter; if parameter = parameter; if parameter = parameter; if parameter () content: var Endpoint a collective (“accounts”) Create().auth(.$user) is a method to authenticate a user. ReadAll().auth(.$user) ReadOne(parameter.id).auth(.$user) Group(parameter.id) Update(parameter.id).auth(.$user) Delete(parameter.id).auth(.$user) Delete(parameter.id).auth(.$user)

After you’ve created your Swift project, you’ll need to add the dependencies for Corvus and a Fluent database driver of your choice to the Package.Swift file. An SQLite driver is used in the following example:

import swift-tools-version:5.2 let package = Package( name: “XpenseServer”, platforms: [.macOS(.v10 15) ] , dependencies: [.package(url: “https://github.com/Apodini/corvus.git”, from: “0.0.14”),.package(url: “https://github.com/vapor/vapor.git”, from: “4.0.0”),.package(url: “https://github.com/vapor/fluent-sqlite-driver.git”, from: “4.0.0-rc”) , targets: [.target(name: “Run”, dependencies: [.target(name: “XpenseServer”) ]),.target(name: “XpenseServer”, dependencies: [.target(name: “Corvus”, package: “corvus”),.product(name: “FluentSQLiteDriver”, package: “fluent-sqlite-driver”),.testTarget(name: “X

Additionally, two setup functions must be present in the application’s Source folder (by default, Sources/App):

configure.swift, where you may set up the application’s middlewares, databases, and migrations:

Corvus import import import FluentSQLiteDriver public func configure(_ app: Application) Vapor import FluentSQLiteDriver public func configure(_ app: Application) app.middleware is thrown. app.middleware.use(CorvusUser.authenticator()) app.databases.use(CorvusToken.authenticator()) use(.sqlite(.file(“db.sqlite”)), as:.sqlite) app.migrations.add(CreateAccount()) app.migrations.add(CreateAccount()) app.migrations.add(CreateAccount()) app.migrations.add(CreateAccount()) app.migrations.add(CreateAccount()) app.migration app.migrations.add(CreateTransaction()) app.migrations.add(CreateCorvusUser()) try app.autoMigrate(CreateCorvusToken()) (). wait() is a function that waits for something to happen.

In addition, there are routes. quick, which registers the Corvus API’s routes:

Corvus import import Try app.register(collection: xpenseApi) in Vapor public func routes(_ app: Application).

Finally, the main.swift file (which is typically located in the Sources/Run folder) should look like this:

app import import Try Environment using Vapor var environment. detect() LoggingSystem is a good option. let app = Application(environment) attempt configure bootstrap(from: &environment) (app) Routes should be tried (app) try app.shutdown() instead of deferring app.shutdown() run()

In general, there are two kinds of Corvus API building blocks: Components that offer specific functionality, such as Create or ReadAll, or group components that enable users to group several groups or concrete endpoints under a single route path. To understand more, go through the documentation and the sample project.

For donation formalities, see our contribution rules.

Freepik created the logo.

Vapor

Fluent

GitHub

https://github.com/Apodini/corvus

The vapor swift is a server-side framework that uses Swift to create declarative, functional and reactive applications.

Related Tags

  • server-side swift future
  • server-side swift in production
  • server-side swift vapor
  • swift server-side 2021
  • server-side swift with vapor pdf