All Projects → twof → VaporCRUDRouter

twof / VaporCRUDRouter

Licence: other
A Rails-inspired extension to Vapor's routing system

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to VaporCRUDRouter

OrderSystem
An independent micro-service that takes orders in and processes payments.
Stars: ✭ 16 (-72.41%)
Mutual labels:  vapor, vapor-swift
VaporGCM
A simple Android GCM/FCM library for Swift/Vapor
Stars: ✭ 25 (-56.9%)
Mutual labels:  vapor, vapor-swift
vapor-queues-fluent-driver
A Fluent implementation for https://github.com/vapor/queues (Vapor4)
Stars: ✭ 17 (-70.69%)
Mutual labels:  vapor-swift, vapor-4
puffery
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
Stars: ✭ 17 (-70.69%)
Mutual labels:  vapor, vapor-swift
routing-kit
🚍 High-performance trie-node router.
Stars: ✭ 95 (+63.79%)
Mutual labels:  vapor, routing
submissions
Provides a common structure to deal with data based API requests
Stars: ✭ 15 (-74.14%)
Mutual labels:  vapor, vapor-4
JSONAPISerializer
JSONAPISerializer for Server Side Swift
Stars: ✭ 21 (-63.79%)
Mutual labels:  vapor, vapor-swift
VaporElasticsearch
A Vapor/Swift Elasticsearch client
Stars: ✭ 26 (-55.17%)
Mutual labels:  vapor, vapor-swift
template
A Vapor template for convenient and fast scaffolding 🏎
Stars: ✭ 33 (-43.1%)
Mutual labels:  vapor, vapor-swift
xcode-leaf-color-schemer
https://ashokgelal.com/2017/01/19/leaf_color_schemer_xcode/?ref=github
Stars: ✭ 26 (-55.17%)
Mutual labels:  vapor, vapor-swift
router-example
Use React Router DOM to create a Single Page Application (SPA).
Stars: ✭ 50 (-13.79%)
Mutual labels:  routing
angular-httpclient
Angular 15 Example HttpClient
Stars: ✭ 21 (-63.79%)
Mutual labels:  routing
cumulus
Cumulus is a high-level Dart framework that makes developing application logic on top of Firebase quick and simple.
Stars: ✭ 14 (-75.86%)
Mutual labels:  routing
next-route-resolver
Declarative route definition for Next.js
Stars: ✭ 58 (+0%)
Mutual labels:  routing
wkhtmltopdf
Generate and return PDFs from Vapor views
Stars: ✭ 53 (-8.62%)
Mutual labels:  vapor
pocketinternet
A Pocket Internet for teaching how the Internet really works.
Stars: ✭ 28 (-51.72%)
Mutual labels:  routing
route pattern generator
A Dart static code generator that produces matchers and builders from route uri patterns.
Stars: ✭ 31 (-46.55%)
Mutual labels:  routing
Mignis
Mignis is a semantic based tool for firewall configuration.
Stars: ✭ 43 (-25.86%)
Mutual labels:  routing
vpc-peering-operator
A Kubernetes Operator to manage the lifecycle of AWS VPC Peering Connections
Stars: ✭ 23 (-60.34%)
Mutual labels:  routing
router
An Fully Automatic RESTful PHP Router
Stars: ✭ 51 (-12.07%)
Mutual labels:  routing

CrudRouter

CrudRouter is a Rails-inspired extension to Vapor's routing system that makes it as simple as possible to set up CRUD (Create, Read, Update, Delete) routes for any Model. CrudRouter provides an API very similar to Rails' resources but with a few extra features including automatic responder generation and type safety.

Installation

Within your Package.swift

dependencies: [
    .package(url: "https://github.com/twof/VaporCRUDRouter.git", from: "1.0.0")
]

and

targets: [
    .target(name: "App", dependencies: ["CrudRouter"]),
]

Usage

Within your router setup (routes.swift in the default Vapor API template)

router.crud(register: Todo.self)

That's it!

That one line gets you the following routes.

GET     /todo       // returns all Todos
GET     /todo/:id   // returns the Todo with :id
POST    /todo       // create new Todo with provided body
PUT     /todo/:id   // update Todo with :id
DELETE  /todo/:id   // delete Todo with :id

Generated paths default to using lower snake case so for example, if you were to do

router.crud(register: SchoolTeacher.self)

you'd get routes like

GET     /school_teacher
GET     /school_teacher/:id
POST    /school_teacher
PUT     /school_teacher/:id
DELETE  /school_teacher/:id

Path Configuration

If you'd like to supply your own path rather than using the name of the supplied model, you can also do that

router.crud("account", register: User.self)

results in

GET     /account
GET     /account/:id
POST    /account
PUT     /account/:id
DELETE  /account/:id

Nested Relations

Say you had a model User, which was the parent of another model Todo. If you'd like routes to expose all Todos that belong to a specific User, you can do something like this.

router.crud(register: User.self) { controller in
    controller.crud(children: \.todos)
}

results in

GET     /user
GET     /user/:id
POST    /user
PUT     /user/:id
DELETE  /user/:id

GET     /user/:id/todo      // returns all Todos belonging to the User with :id
GET     /user/:id/todo/:id  // returns the Todo with :id belonging to the User with :id
POST    /user/:id/todo      // creates a new Todo belonging to the User with :id
PUT     /user/:id/todo/:id  // updates the Todo with :id belonging to the User with :id
DELETE  /user/:id/todo/:id  // deletes the Todo with :id belonging to the User with :id

within the supplied closure, you can also expose routes for related Parents and Siblings

controller.crud(children: \.todos)
controller.crud(parent: \.todos)
controller.crud(siblings: \.todos)

Including or Excluding Specific Routes

If you'd like to register a Model, but you don't want every route to be available, you can specify the ones you want, or exclude the ones you don't.

router.crud(register: Todo.self, .except([.create, .delete])) { controller in
    controller.crud(parent: \.owner, .only([.read]))
}

results in

PUT /todo/:id
GET /todo/:id
GET /todo

GET /todo/:id/tag/:id

Future features

  • query parameter support
  • PATCH support
  • automatically expose relations (blocked by lack of Swift reflection support)
  • generate models and rest routes via console command
  • Publicable support (potentially blocked by a compiler bug)
  • Fine grained per route public return models
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].