Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/apodini/corvus

Corvus has been archived in favor of https://github.com/Apodini/Apodini .
https://github.com/apodini/corvus

backend corvus databases declarative rest rest-api server swift vapor

Last synced: about 1 month ago
JSON representation

Corvus has been archived in favor of https://github.com/Apodini/Apodini .

Awesome Lists containing this project

README

        

# Corvus





Documentation


MIT License


Continuous Integration


Swift 5.2


Corvus is the first truly declarative server-side framework for Swift. It provides a declarative, composable syntax which makes it easy to get APIs up and running. It is based heavily on the existing work from [Vapor](https://github.com/vapor/vapor).

# Example

Below is an example of a full-featured API that manages Bank Accounts and Transactions belonging to certain users. It also showcases the ease of using authentication and setting authorization rules for specific routes.

```Swift
let xpenseApi = Api("api") {
User("users")

Login("login")

BearerAuthGroup {
AccountsEndpoint()
TransactionsEndpoint()
}
}
```

Because Corvus is composable, it is easy to use a group of components as its own component:
```Swift
final class AccountsEndpoint: Endpoint {
let parameter = Parameter()

var content: Endpoint {
Group("accounts") {
Create().auth(\.$user)
ReadAll().auth(\.$user)

Group(parameter.id) {
ReadOne(parameter.id).auth(\.$user)
Update(parameter.id).auth(\.$user)
Delete(parameter.id).auth(\.$user)
}
}
}
}
```

# How to set up

After your Swift Project, in the `Package.Swift` file, you will need to add the dependencies
for `Corvus` and a `Fluent` database driver of your choice. Below is an example with an
`SQLite` driver:

```Swift
// swift-tools-version:5.2
import PackageDescription

let package = Package(
name: "XpenseServer",
platforms: [
.macOS(.v10_15)
],
products: [
.library(name: "XpenseServer", targets: ["XpenseServer"])
],
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: [
.product(name: "Corvus", package: "corvus"),
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver")
]),
.testTarget(name: "XpenseServerTests",
dependencies: [
.target(name: "XpenseServer"),
.product(name: "XCTVapor", package: "vapor"),
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver")
])
]
)
```

Additionally, under the application's `Source` folder (by default that is `Sources/App`), two setup functions need to be present:

`configure.swift`, in which you can configure middlewares, databases and migrations used
in the application:

```Swift
import Corvus
import Vapor
import FluentSQLiteDriver

public func configure(_ app: Application) throws {
app.middleware.use(CorvusUser.authenticator())
app.middleware.use(CorvusToken.authenticator())

app.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite)
app.migrations.add(CreateAccount())
app.migrations.add(CreateTransaction())
app.migrations.add(CreateCorvusUser())
app.migrations.add(CreateCorvusToken())

try app.autoMigrate().wait()
}
```

And `routes.swift`, which registers the routes from the `Corvus` API:
```Swift
import Corvus
import Vapor

public func routes(_ app: Application) throws {
try app.register(collection: xpenseApi)
}
```

Finally the application's `main.swift` file (which is usually under the path `Sources/Run`) should look like this:

```Swift
import App
import Vapor

var environment = try Environment.detect()
try LoggingSystem.bootstrap(from: &environment)
let app = Application(environment)
try configure(app)
try routes(app)
defer {
app.shutdown()
}
try app.run()
```

# How to use

In general, there are two types of building blocks for a `Corvus` API: Group components, which
allow users to group more groups or concrete endpoints under a common route path, or
components that provide concrete functionality, like `Create` or `ReadAll`. Check out the
[docs](https://apodini.github.io/corvus/) and the [example project](https://github.com/Apodini/corvus-example-project) to learn more!

# How to contribute

Review our [contribution guidelines](https://github.com/Apodini/.github/blob/release/CONTRIBUTING.md) for contribution formalities.

# Sources
The logo: Made by [Freepik](https://www.flaticon.com/authors/freepik)

[Vapor](https://github.com/vapor/vapor)

[Fluent](https://github.com/vapor/fluent)