Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 .
- Host: GitHub
- URL: https://github.com/apodini/corvus
- Owner: Apodini
- License: mit
- Archived: true
- Created: 2020-01-23T12:17:29.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2020-07-21T12:40:23.000Z (over 4 years ago)
- Last Synced: 2024-07-31T15:02:17.932Z (4 months ago)
- Topics: backend, corvus, databases, declarative, rest, rest-api, server, swift, vapor
- Language: Swift
- Homepage: https://github.com/Apodini/Apodini
- Size: 451 KB
- Stars: 39
- Watchers: 7
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-result-builders - Corvus
- awesome-swift - Corvus - Meet Corvus, the first strongly declarative server-side framework. ` 📝 a year ago` (Network [🔝](#readme))
README
# Corvus
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 PackageDescriptionlet 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 FluentSQLiteDriverpublic 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 Vaporpublic 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 Vaporvar 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)