All Projects → derekdowling → go-json-spec-handler

derekdowling / go-json-spec-handler

Licence: MIT license
Simple JSON API Spec Compatibility in Golang

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-json-spec-handler

RESTEasy
REST API calls made easier
Stars: ✭ 12 (-70.73%)
Mutual labels:  json-api, api-client
JSON-API-Client
Abstract client-side php implementation of the json api specification (jsonapi.org)
Stars: ✭ 17 (-58.54%)
Mutual labels:  json-api, api-client
DummyJSON
DummyJSON provides different types of REST Endpoints filled with JSON data which you can use in developing the frontend with your favorite framework and library without worrying about writing a backend.
Stars: ✭ 213 (+419.51%)
Mutual labels:  json-api, api-client
Kitsu
🦊 A simple, lightweight & framework agnostic JSON:API client
Stars: ✭ 166 (+304.88%)
Mutual labels:  json-api, api-client
FSharp.JsonApi
Use F# to create and consume flexible, strongly typed web APIs following the JSON:API specification
Stars: ✭ 20 (-51.22%)
Mutual labels:  json-api
GetJSON
GetJson is the simplest HTTP library to Receive JSON Data from REST Service.
Stars: ✭ 18 (-56.1%)
Mutual labels:  json-api
ck-analytics
Collective Knowledge repository with actions to unify the access to different predictive analytics engines (scipy, R, DNN) from software, command line and web-services via CK JSON API:
Stars: ✭ 35 (-14.63%)
Mutual labels:  json-api
jsonapi-serializable
Conveniently build and efficiently render JSON API resources.
Stars: ✭ 43 (+4.88%)
Mutual labels:  json-api
cv4pve-api-php
Proxmox VE Client API for PHP
Stars: ✭ 45 (+9.76%)
Mutual labels:  api-client
dynamic-cli
A Modern, user-friendly command-line HTTP client for the API testing, and if you're stuck - Search and browse StackOverflow without leaving the CLI
Stars: ✭ 151 (+268.29%)
Mutual labels:  api-client
BarterOnly
An ecommerce platform to buy or exchange items at your convenience
Stars: ✭ 16 (-60.98%)
Mutual labels:  json-api
Characters of the Three Kingdoms
3️⃣ Characters of the Three Kingdoms - 三国人物结构化数据
Stars: ✭ 100 (+143.9%)
Mutual labels:  json-api
QuickLearn
A collection of resources categorised by tech domains, languages, expertise and much more. QuickLearn gives you a quick access to all the resources that you could need at a single place, within a click!
Stars: ✭ 89 (+117.07%)
Mutual labels:  json-api
fire
An idiomatic micro-framework for building Ember.js compatible APIs with Go.
Stars: ✭ 56 (+36.59%)
Mutual labels:  json-api
alpha-vantage-api
Alpha Vantage PHP Client
Stars: ✭ 57 (+39.02%)
Mutual labels:  api-client
json-api
Framework agnostic JSON API serialisation and deserialisation
Stars: ✭ 40 (-2.44%)
Mutual labels:  json-api
ck-crowd-scenarios
Public scenarios to crowdsource experiments (such as DNN crowd-benchmarking and crowd-tuning) using Collective Knowledge Framework across diverse mobile devices provided by volunteers. Results are continuously aggregated at the open repository of knowledge:
Stars: ✭ 22 (-46.34%)
Mutual labels:  json-api
samp-client
GTA SA-MP API client library for Python
Stars: ✭ 21 (-48.78%)
Mutual labels:  api-client
json-api-react-redux-example
React Application With Redux And JSON API
Stars: ✭ 25 (-39.02%)
Mutual labels:  json-api
json-api-response-converter
Normalize your JSON:API response
Stars: ✭ 21 (-48.78%)
Mutual labels:  json-api

A Go JSONAPI Specification Handler

GoDoc Travis CI Go Report Card TestCoverage

A (de)serialization handler for writing JSON API Specification compatible software in Go. Works with Ember/Ember-Data too!

Contents

  1. JSH
  1. JSC
  2. JSH-API

jsh - JSON Specification Handler

For streamlined JSONAPI object serialization. Uses govalidator for input validation.

import github.com/derekdowling/go-json-spec-handler

type User struct {
  // valid from github.com/asaskevich/govalidator gives us input validation
  // when object.Unmarshal() is invoked on this type
  Name string `json:"name" valid:"alphanum"`
}

// example http.HandlerFunc for PATCH /users/1
func PatchUser(w http.ResponseWriter, r *http.Request) {

  // performs Specification checks against the request
  object, err := jsh.ParseObject(r)
  if err != nil {
    // jsh returns API friendly errors, that are easy to respond with
    jsh.Send(w, r, err)
    return
  }

  // use object.ID to look up user/do business logic
  user := &User{}
  
  // unmarshal data into relevant internal types if govalidator passes, otherwise
  // return the pre-formatted HTTP 422 error to signify how the input failed
  err = object.Unmarshal("users", user)
  if err != nil {
    jsh.Send(w, r, err)
    return
  }

  // modify your resource object
  user.Name = "Bob"

  // repackage and send the updated resource as a response
  err = object.Marshal(user)
  if err != nil {
    jsh.Send(w, r, err)
    return
  }

  jsh.Send(w, r, object)
}

Motivation for JSH

JSH was written for tackling the issue of dealing with Ember-Data within a pre-existing API server. In sticking with Go's philosophy of modules over frameworks, it is intended to be a drop in serialization layer focusing only on parsing, validating, and sending JSONAPI compatible responses.

Features

Implemented:

- Handles both single object and array based JSON requests and responses
- Input validation with HTTP 422 Status support via [go-validator](https://github.com/go-validator/validator)
- Client request validation with HTTP 406 Status responses
- Links, Relationship, Meta fields
- Prepackaged error responses, easy to use Internal Service Error builder
- Smart responses with correct HTTP Statuses based on Request Method and HTTP Headers
- HTTP Client for GET, POST, DELETE, PATCH

TODO:

- [Reserved character checking](http://jsonapi.org/format/upcoming/#document-member-names-reserved-characters)

Not Implementing:

* These features aren't handled because they are beyond the scope of what
  this module is meant to achieve. See [jshapi](https://github.com/derekdowling/go-json-spec-handler/tree/master/jsh-api)
  for a full-fledged API solution that solves many of these problems.

- Routing
- Sorting
- Pagination
- Filtering
- ORM

Stability

jsh has a mostly stabilized core data document model. At this point in time I am not yet ready to declare v1, but am actively trying to avoid breaking the public API. The areas most likely to receive improvement include relationship, link, and metadata management. At this point in time I can confidentally suggest you use jsh without risking major upgrade incompatibility going forward!

jsc - JSON Specification Client

A HTTP JSONAPI Client for making outbound server requests. Built on top of http.Client and jsh:

import github.com/derekdowling/go-json-spec-handler/client

// GET http://your.api/users/1
document, resp, err := jsc.Fetch("http://your.api/", "users", "1")
object := doc.First()

user := &yourUser{}
err := object.Unmarshal("users", user)

JSH-API

If you're looking for a good place to start with a new API, I've since created jshapi which builds on top of Goji 2 and jsh in order to handle the routing structure that JSON API requires as well as a number of other useful tools for testing and mocking APIs as you develop your own projects. JSHAPI is similar in spirit to this project as it inteniontally focuses on eliminating boilerplate from your projects without trying to solve all of the world's problems.

Examples

There are lots of great examples in the tests themselves that show exactly how jsh works. The godocs as linked above have a number of examples in them as well.

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