All Projects → qvantel → jsonapi-scala

qvantel / jsonapi-scala

Licence: BSD-3-Clause License
jsonapi.org library for scala

Programming Languages

scala
5932 projects

Labels

Projects that are alternatives of or similar to jsonapi-scala

Jsonapi Rb
Efficiently produce and consume JSON API documents.
Stars: ✭ 219 (+895.45%)
Mutual labels:  jsonapi
JSONAPISerializer
JSONAPISerializer for Server Side Swift
Stars: ✭ 21 (-4.55%)
Mutual labels:  jsonapi
ember-custom-actions
Custom API actions for Ember applications
Stars: ✭ 73 (+231.82%)
Mutual labels:  jsonapi
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+1000%)
Mutual labels:  jsonapi
fire
An idiomatic micro-framework for building Ember.js compatible APIs with Go.
Stars: ✭ 56 (+154.55%)
Mutual labels:  jsonapi
jsonapi-client
A convenient module to consume a jsonapi service
Stars: ✭ 38 (+72.73%)
Mutual labels:  jsonapi
Json Api
Implementation of JSON API in PHP 7
Stars: ✭ 171 (+677.27%)
Mutual labels:  jsonapi
kurier
TypeScript framework to create JSON:API compliant APIs
Stars: ✭ 30 (+36.36%)
Mutual labels:  jsonapi
FSharp.JsonApi
Use F# to create and consume flexible, strongly typed web APIs following the JSON:API specification
Stars: ✭ 20 (-9.09%)
Mutual labels:  jsonapi
laravel5-hal-json
Laravel 5 HAL+JSON API Transformer Package
Stars: ✭ 15 (-31.82%)
Mutual labels:  jsonapi
django-jsonapi-training
Columbia University IT developer training on using Django, REST and {json:api}
Stars: ✭ 25 (+13.64%)
Mutual labels:  jsonapi
jsonapi-serializable
Conveniently build and efficiently render JSON API resources.
Stars: ✭ 43 (+95.45%)
Mutual labels:  jsonapi
json-server
Create a dummy REST API from a json file with zero coding in seconds
Stars: ✭ 34 (+54.55%)
Mutual labels:  jsonapi
Waterwheel.js
A generic JavaScript helper library to query and manipulate Drupal 8 via core REST and JSON API
Stars: ✭ 237 (+977.27%)
Mutual labels:  jsonapi
json-api-serializer
Node.js/browser framework agnostic JSON API (http://jsonapi.org/) serializer.
Stars: ✭ 141 (+540.91%)
Mutual labels:  jsonapi
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (+768.18%)
Mutual labels:  jsonapi
market place api 6
Code example of API on Rails 6 book https://github.com/madeindjs/api_on_rails
Stars: ✭ 18 (-18.18%)
Mutual labels:  jsonapi
json-api-doc
JSON API parser returning a simple Python dictionary
Stars: ✭ 24 (+9.09%)
Mutual labels:  jsonapi
php-json-schema-model-generator
Creates (immutable) PHP model classes from JSON-Schema files including all validation rules as PHP code
Stars: ✭ 36 (+63.64%)
Mutual labels:  jsonapi
jsonapi-serializer-formats
💎 Gem to enrich jsonapi-serializer with multiple formats
Stars: ✭ 20 (-9.09%)
Mutual labels:  jsonapi

http://jsonapi.org/ implementation in scala

Build Status codecov Maven Central

Features

  • Automatic generation of jsonapi json writers with relationship handling for case classes

Requirements

  • Tested to work on Scala 2.12.10 or 2.13.3
  • If you are using Scala 2.12 use the macro paradise plugin. Add addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full) into your build.sbt somewhere.
    If you are using Scala 2.13 you should instead use the compiler flag -Ymacro-annotations.
    An example for handling cross-compiling with both can be found in project/MacrosCompiler.

Example

import _root_.spray.json.DefaultJsonProtocol._
import com.qvantel.jsonapi._

implicit val apiRoot: ApiRoot = ApiRoot(None)

@jsonApiResource final case class Employee(id: String, name: String)
@jsonApiResource final case class Company(id: String, name: String, employees: ToMany[Employee])

val acme = Company("1", "acme", ToMany.loaded(Seq(Employee("1", "number one 1"))))

val json = rawOne(acme)
val parsed = readOne[Company](json, Set("employees"))

acme == parsed // true

or see https://github.com/Doikor/jsonapi-scala-example

Known issues

  • loop handing on reader side (relationship path has to be given manually)

JsonApiClient

There is a very generic JsonApiClient interface for implementing a simple client interface for handling the http query writing side of this

The subproject "akka-client" has an implementation of this using akka-http

The subproject "http4s-client" has an implementation of this using http4s

Usage

import cats.data.OptionT
import com.qvantel.jsonapi.JsonApiClient

val jac = JsonApiClient.instance // won't work if you don't have an actual implementations stuff in scope. See setup.

val one: IO[Option[BillingAccount]] = jac.one[BillingAccount]("ba1") 
val many: IO[List[BillingAccount]] = jac.many[BillingAccount](Set("ba1", "ba2"))

// can also load includes at the same time
val withIncludes = jac.one[BillingAccount]("ba1", Set("customer-account"))

// includes can also be loaded on their own with a method
val ba: OptionT[IO, BillingAccount]  = OptionT(jac.one[BillingAccount]("ba"))
val ca: OptionT[IO, CustomerAccount] = ba.semiflatMap(_.customerAccount.load)

// filtering support
val filtered = jac.filter[BillingAccount]("some nice filter string here")

Setup

akka-http client

// needs ActorSystem and Materializer for akka-http
// the ApiEndPoint is used to as the "root" where to launch queries
import io.lemonlabs.uri.typesafe.dsl._
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.qvantel.jsonapi.ApiEndpoint
import com.qvantel.jsonapi.JsonApiClient
import com.qvantel.jsonapi.client.akka.AkkaClient._

implicit val system: ActorSystem  = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api")

val jac = JsonApiClient.instance

http4s client

Setup for http4s client

import io.lemonlabs.uri.typesafe.dsl._
import org.http4s.client.Client
import org.http4s.client.blaze.Http1Client
import cats.effect.IO
import com.qvantel.jsonapi.ApiEndpoint
import com.qvantel.jsonapi.JsonApiClient

import com.qvantel.jsonapi.client.http4s.Http4sClient._
import com.qvantel.jsonapi.client.http4s.JsonApiInstances._


implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api")

implicit val client: Client[IO] = Http1Client[IO]().unsafeRunSync()

val jac = JsonApiClient.instance
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].