All Projects → mattpolzin → Jsonapi

mattpolzin / Jsonapi

Licence: mit
Swift Codable JSON:API framework

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Jsonapi

Laravel Jsonapi
Basic setup framework for creating a Laravel JSON-API server
Stars: ✭ 16 (-69.81%)
Mutual labels:  json-api
Server
Serve your Rubix ML models in production with scalable stand-alone model inference servers.
Stars: ✭ 30 (-43.4%)
Mutual labels:  json-api
Libgenerics
libgenerics is a minimalistic and generic library for C basic data structures.
Stars: ✭ 42 (-20.75%)
Mutual labels:  generic
Reproduce Ck Paper
Shared artifacts in the Collective Knowledge Format as a proof-of-concept to reproduce our recent Collective Mind- and Collective Knowledge-related papers
Stars: ✭ 24 (-54.72%)
Mutual labels:  json-api
Authnetjson
Library that abstracts Authorize.Net's JSON APIs. This includes the Advanced Integration Method (AIM), Automated Recurring Billing (ARB), Customer Information Manager (CIM), Transaction Reporting, Simple Integration Method (SIM), and Webhooks.
Stars: ✭ 14 (-73.58%)
Mutual labels:  json-api
Grocery Cms Php Restful Api
Grocery-CMS-PHP-Restful-API is an online grocery shop. The project is developed by using PHP/MySQL/Slim Restful API. The project has powerful backend cms to manage grocery shop online. it has features like add items, remove items, update price, manage orders etc. Restful API ready to embed in Application using JSON data.
Stars: ✭ 36 (-32.08%)
Mutual labels:  json-api
Graphiti
Stylish Graph APIs
Stars: ✭ 783 (+1377.36%)
Mutual labels:  json-api
Mobx Jsonapi Store
JSON API Store for MobX
Stars: ✭ 52 (-1.89%)
Mutual labels:  json-api
Apicasso
An abstract API design as a Rails-based mountable engine
Stars: ✭ 27 (-49.06%)
Mutual labels:  json-api
Usermanager React Native
Login and Signup system with PHP/MySQL and Json in React native
Stars: ✭ 42 (-20.75%)
Mutual labels:  json-api
Tns Restful Json Api
This is the code repository that goes along with the "TheNewStack" article for RESTful JSON API post
Stars: ✭ 846 (+1496.23%)
Mutual labels:  json-api
Inquisitor jsonapi
JSON API Matchers for Inquisitor
Stars: ✭ 13 (-75.47%)
Mutual labels:  json-api
Roar Jsonapi
JSON API support for Roar.
Stars: ✭ 40 (-24.53%)
Mutual labels:  json-api
Django Rest Framework Json Api
JSON API support for Django REST Framework
Stars: ✭ 898 (+1594.34%)
Mutual labels:  json-api
Dashboard Server
A JSON file RESTful API with authorization based on json-server
Stars: ✭ 48 (-9.43%)
Mutual labels:  json-api
Forbes400
JSON Api Of The Forbes 400 Richest People List
Stars: ✭ 7 (-86.79%)
Mutual labels:  json-api
Alembic
JSONAPI 1.0 Elixir library
Stars: ✭ 31 (-41.51%)
Mutual labels:  json-api
Json Api Dart
JSON:API client for Dart/Flutter
Stars: ✭ 53 (+0%)
Mutual labels:  json-api
Jsonapi parameters
Rails-way to consume JSON:API input
Stars: ✭ 50 (-5.66%)
Mutual labels:  json-api
Processmemoryutilities.net
Implements performant ReadProcessMemory and WriteProcessMemory with generic type parameters using InlineIL
Stars: ✭ 42 (-20.75%)
Mutual labels:  generic

JSONAPI

MIT license Swift 5.2+ Build Status

A Swift package for encoding to- and decoding from JSON API compliant requests and responses.

See the JSON API Spec here: https://jsonapi.org/format/

Quick Start

⚠️ The following Google Colab examples have correct code, but from time to time the Google Colab Swift compiler may be buggy and claim it cannot build the JSONAPI library.

Clientside

Serverside

Client+Server

This library works well when used by both the server responsible for serialization and the client responsible for deserialization. Check out the example.

Table of Contents

Primary Goals

The primary goals of this framework are:

  1. Allow creation of Swift types that are easy to use in code but also can be encoded to- or decoded from JSON API v1.0 Spec compliant payloads without lots of boilerplate code.
  2. Leverage Codable to avoid additional outside dependencies and get operability with non-JSON encoders/decoders for free.
  3. Do not sacrifice type safety.
  4. Be platform agnostic so that Swift code can be written once and used by both the client and the server.
  5. Provide human readable error output. The errors thrown when decoding an API response and the results of the JSONAPITesting framework's compare(to:) functions all have digestible human readable descriptions (just use String(describing:)).

Caveat

The big caveat is that, although the aim is to support the JSON API spec, this framework ends up being naturally opinionated about certain things that the API Spec does not specify. These caveats are largely a side effect of attempting to write the library in a "Swifty" way.

If you find something wrong with this library and it isn't already mentioned under Project Status, let me know! I want to keep working towards a library implementation that is useful in any application.

Dev Environment

Prerequisites

  1. Swift 5.2+
  2. Swift Package Manager, Xcode 11+, or Cocoapods

Swift Package Manager

Just include the following in your package's dependencies and add JSONAPI to the dependencies for any of your targets.

.package(url: "https://github.com/mattpolzin/JSONAPI.git", from: "5.0.0")

Xcode project

With Xcode 11+, you can open the folder containing this repository. There is no need for an Xcode project, but you can generate one with swift package generate-xcodeproj.

CocoaPods

To use this framework in your project via Cocoapods, add the following dependencies to your Podfile.

pod 'Poly', :git => 'https://github.com/mattpolzin/Poly.git'
pod 'MP-JSONAPI', :git => 'https://github.com/mattpolzin/JSONAPI.git'

Carthage

This library does not support the Carthage package manager. This is intentional to avoid an additional dependency on Xcode and the Xcode's project files as their format changes throughout versions (in addition to the complexity of maintaining different shared schemes for each supported operating system).

The difference between supporting and not supporting Carthage is the difference between maintaining an Xcode project with at least one shared build scheme; I encourage those that need Carthage support to fork this repository and add support to their fork by committing an Xcode project (you can generate one as described in the Xcode project section above). Once an Xcode project is generated, you need to mark at least one scheme as shared.

Running the Playground

To run the included Playground files, create an Xcode project using Swift Package Manager, then create an Xcode Workspace in the root of the repository and add both the generated Xcode project and the playground to the Workspace.

Note that Playground support for importing non-system Frameworks is still a bit touchy as of Swift 4.2. Sometimes building, cleaning and building, or commenting out and then uncommenting import statements (especially in theEntities.swift Playground Source file) can get things working for me when I am getting an error about JSONAPI not being found.

Deeper Dive

JSONAPI+Testing

The JSONAPI framework is packaged with a test library to help you test your JSONAPI integration. The test library is called JSONAPITesting. You can see JSONAPITesting in action in the Playground included with the JSONAPI repository.

Literal Expressibility

Literal expressibility for Attribute, ToOneRelationship, and Id are provided so that you can easily write test ResourceObject values into your unit tests.

For example, you could create a mock Author (from the above example) as follows

let author = Author(
	id: "1234", // You can just use a String directly as an Id
	attributes: .init(name: "Janice Bluff"), // The name Attribute does not need to be initialized, you just use a String directly.
	relationships: .none,
	meta: .none,
	links: .none
)

Resource Object check()

The ResourceObject gets a check() function that can be used to catch problems with your JSONAPI structures that are not caught by Swift's type system.

To catch malformed JSONAPI.Attributes and JSONAPI.Relationships, just call check() in your unit test functions:

func test_initAuthor() {
	let author = Author(...)
	Author.check(author)
}

Comparisons

You can compare Documents, ResourceObjects, Attributes, etc. and get human-readable output using the compare(to:) methods included with JSONAPITesting.

func test_articleResponse() {
	let endToEndAPITestResponse: SingleArticleDocumentWithIncludes = ...

	let expectedResponse: SingleArticleDocumentWithIncludes = ...

	let comparison = endToEndAPITestResponse.compare(to: expectedResponse)

	XCTAssert(comparison.isSame, String(describing: comparison))
}

JSONAPI-Arbitrary

The JSONAPI-Arbitrary library provides SwiftCheck Arbitrary conformance for many of the JSONAPI types.

See https://github.com/mattpolzin/JSONAPI-Arbitrary for more information.

JSONAPI-OpenAPI

The JSONAPI-OpenAPI library generates OpenAPI compliant JSON Schema for models built with the JSONAPI library. If your Swift code is your preferred source of truth for API information, this is an easy way to document the response schemas of your API.

JSONAPI-OpenAPI also has experimental support for generating JSONAPI Swift code from Open API documentation (this currently lives on the feature/gen-swift branch).

See https://github.com/mattpolzin/JSONAPI-OpenAPI for more information.

JSONAPI-ResourceStorage

The JSONAPI-ResourceStorage package has two very early stage modules supporting storage and retrieval of JSONAPI.ResourceObjects. Please consider these modules to be more of examples of two directions you could head in than anything else.

https://github.com/mattpolzin/JSONAPI-ResourceStorage

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