All Projects → aonawale → JSONAPISerializer

aonawale / JSONAPISerializer

Licence: MIT license
JSONAPISerializer for Server Side Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to JSONAPISerializer

template
A Vapor template for convenient and fast scaffolding 🏎
Stars: ✭ 33 (+57.14%)
Mutual labels:  vapor, vapor-swift
OrderSystem
An independent micro-service that takes orders in and processes payments.
Stars: ✭ 16 (-23.81%)
Mutual labels:  vapor, vapor-swift
VaporGCM
A simple Android GCM/FCM library for Swift/Vapor
Stars: ✭ 25 (+19.05%)
Mutual labels:  vapor, vapor-swift
VaporElasticsearch
A Vapor/Swift Elasticsearch client
Stars: ✭ 26 (+23.81%)
Mutual labels:  vapor, vapor-swift
puffery
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
Stars: ✭ 17 (-19.05%)
Mutual labels:  vapor, vapor-swift
xcode-leaf-color-schemer
https://ashokgelal.com/2017/01/19/leaf_color_schemer_xcode/?ref=github
Stars: ✭ 26 (+23.81%)
Mutual labels:  vapor, vapor-swift
VaporCRUDRouter
A Rails-inspired extension to Vapor's routing system
Stars: ✭ 58 (+176.19%)
Mutual labels:  vapor, vapor-swift
jsonapi-serializable
Conveniently build and efficiently render JSON API resources.
Stars: ✭ 43 (+104.76%)
Mutual labels:  jsonapi
KarmaAPI
Swift API using the Vapor web framework and Turnstile for authentication
Stars: ✭ 20 (-4.76%)
Mutual labels:  vapor
wkhtmltopdf
Generate and return PDFs from Vapor views
Stars: ✭ 53 (+152.38%)
Mutual labels:  vapor
web-template
A starting point for web applications
Stars: ✭ 42 (+100%)
Mutual labels:  vapor
fluent-provider
A provider for including Fluent in Vapor applications
Stars: ✭ 13 (-38.1%)
Mutual labels:  vapor
paginator
Offset pagination for Vapor 🗂
Stars: ✭ 67 (+219.05%)
Mutual labels:  vapor
php-serializer
Serialize PHP variables, including objects, in any format. Support to unserialize it too.
Stars: ✭ 47 (+123.81%)
Mutual labels:  jsonapi
swiftybeaver-provider
SwiftyBeaver Logging Provider for Vapor, the server-side Swift web framework https://swiftybeaver.com
Stars: ✭ 32 (+52.38%)
Mutual labels:  vapor
VaporTwilioService
Twilio API provider for all your Vapor needs
Stars: ✭ 19 (-9.52%)
Mutual labels:  vapor
mongodb-vapor
MongoDB + Vapor integration
Stars: ✭ 31 (+47.62%)
Mutual labels:  vapor
fluent-mysql-driver
🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
Stars: ✭ 69 (+228.57%)
Mutual labels:  vapor
sqlite-kit
Non-blocking SQLite client library with SQL builder built on SwiftNIO
Stars: ✭ 51 (+142.86%)
Mutual labels:  vapor
sqlite-nio
Non-blocking wrapper for libsqlite3-dev using SwiftNIO
Stars: ✭ 33 (+57.14%)
Mutual labels:  vapor

JSONAPISerializer for Server Side Swift

Serialize Swift objects into JSONAPI compliant structures.

Basic usage

import JSON
import JSONAPISerializer

struct User: JSONRepresentable {
    var id: Node?
    let firstName: String
    let lastName: String

    func makeJSON() throws -> JSON {
        var json = JSON([:])
        try json.set("id", id)
        try json.set("first-name", firstName)
        try json.set("last-name", lastName)
        return json
    }
}

let config = JSONAPIConfig(type: "users")
let serializer = JSONAPISerializer(config: config)

let users: [User]...
try serializer.serialize(users)

Produces

{
  "data": [{
    "type": "users",
    "id": "1",
    "attributes": {
      "first-name": "foo",
      "last-name": "bar"
    }
  }, {
    "type": "users",
    "id": "2",
    "attributes": {
      "first-name": "John",
      "last-name": "Doe"
    }
  }],
  "jsonapi": {
    "version": "1.0"
  },
  "links": {
    "self": "/users"
  },
  "meta": {}
}

Relationships

let petsConfig = JSONAPIConfig(type: "pets")
let profileConfig = JSONAPIConfig(type: "profiles", relationships: ["pets": petsConfig])
let userConfig = JSONAPIConfig(type: "users", relationships: ["profile": profileConfig])
let serializer = JSONAPISerializer(config: userConfig)

let users: [User]...
try serializer.serialize(users)

Produces

{
  "data": [
    {
      "id": 2,
      "type": "users",
      "attributes": {
        "first-name": "foo",
        "last-name": "bar"
      },
      "relationships": {
        "profile": {
          "data": {
            "id": 2,
            "type": "profiles"
          }
        }
      }
    }
  ],
  "included": [
    {
      "attributes": {
        "age": 18,
        "user-id": 2,
      },
      "id": 2,
      "relationships": {
        "pets": {
          "data": [
            {
              "id": 5,
              "type": "pets"
            },
            {
              "id": 8,
              "type": "pets"
            }
          ]
        }
      },
      "type": "profiles"
    },
    {
      "attributes": {
        "pet-name": "dog",
        "profile-id": 2
      },
      "id": 5,
      "relationships": {},
      "type": "pets"
    },
    {
      "attributes": {
        "pet-name": "cat",
        "profile-id": 2
      },
      "id": 8,
      "relationships": {},
      "type": "pets"
    }
  ],
  "jsonapi": {
    "version": "1.0"
  },
  "links": {
    "self": "/users"
  },
  "meta": {}
}

Roadmap

  • Dasherized, underscored and camel cased keys support.

License

JSONAPISerializer is available under the MIT license. See the LICENSE file for more information.

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].