Swiftpack.co -  KazaiMazai/vapor-rest-kit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
KazaiMazai/vapor-rest-kit
Declarative REST API framework for Vapor
.package(url: "https://github.com/KazaiMazai/vapor-rest-kit.git", from: "1.0.0-beta.2.1")

Sublime's custom image

This package is intended to speed up backend development using server side swift framework Vapor

Features

  • Generic-powered Declarative API
  • CRUD for Resource Models
  • CRUD for Related Resource Models
  • Nested routes for Parent-Child, Siblings relations
  • Nested /me routes for Authenticatable Related Resource
  • API versioning for controllers and Resource Models
  • Pagination for Resource Collections by Cursor or Page
  • Filtering
  • Sorting
  • Eager loading
  • Dynamic query keys for sorting, filtering and eager loading
  • Controller Middlewares for business logic
  • Compound Controllers
  • Fluent Model convenience extensions for models initial migrations
  • Fluent Model convenience extensions for Siblings relations

Installation

Add this package to your Package.swift as dependency and to your target.

dependencies: [
    .package(url: "https://github.com/KazaiMazai/vapor-rest-kit",  from: "1.0.0-beta.1.6")
],
targets: [
    .target(name: "App", dependencies: [
        .product(name: "VaporRestKit", package: "vapor-rest-kit")
    ])
]

Import in your code

import VaporRestKit

  1. Define Input, Output structs for your Model, conforming to ResourceUpdateModel, ResourcePatchModel, ResourceOutputModel protocols:
protocol ResourceUpdateModel: Content, Validatable {
    associatedtype Model: Fields

    func update(_: Model) -> Model
}

protocol ResourcePatchModel: Content, Validatable {
    associatedtype Model: Fields

    func patch(_: Model) -> Model
}

protocol ResourceOutputModel: Content {
    associatedtype Model: Fields

    init(_: Model)
}

  1. Define TodoEagerLoading, TodoSortKeys, TodoFilterKeys if needed

  2. Create controller with RestKit Declarative API:

let controller = Todo.Output
                .controller(eagerLoading: TodoEagerLoading.self)
                .related(with: \Tag.$relatedTodos, relationName: "related")
                .create(using: Todo.Input.self)
                .read()
                .update(using: Todo.Input.self)
                .patch(using: Todo.PatchInput.self)
                .read()
                .delete()
                .collection(sorting: TodoSortKeys.self,
                            filtering: TodoFilterKeys.self)


  1. Add methods to route builder:
let tags = routeBuilder.grouped("tags")
controller.addMethodsTo(tags, on: "todos")
  1. Get result:
HTTP Method Route Result
POST /tags/:tagId/related/todos Create new
GET /tags/:tagId/related/todos/:todoId Show existing
PUT /tags/:tagId/related/todos/:todoId Update existing (Replace)
PATCH /tags/:tagId/related/todos/:todoId Patch exsiting (Partial update)
DELETE /tags/:tagId/related/todos/:todoId Delete
GET /tags/:tagId/related/todos Show list

Check out the Docs for more details:

Basics

Fluent Model Extensions

CRUD for Resource Models

CRUD for Related Resource Models

CRUD for Relations

Controller Middlewares

Combine Controllers

API Versioning

Filtering

Sorting

Eager Loading

Pagination

Licensing

Vapor RestKit is licensed under MIT license.

GitHub

link
Stars: 47
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API