All Projects → scoutforpets → jsonapi-mapper

scoutforpets / jsonapi-mapper

Licence: Unlicense license
JSON API-Compliant Serialization for your Node ORM

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to jsonapi-mapper

Jsonapi Serializer
A Node.js framework agnostic library for (de)serializing your data to JSON API
Stars: ✭ 651 (+1487.8%)
Mutual labels:  json-api, serializer
laravel5-jsonapi-dingo
Laravel5 JSONAPI and Dingo together to build APIs fast
Stars: ✭ 29 (-29.27%)
Mutual labels:  json-api, serializer
json-api-serializer
Node.js/browser framework agnostic JSON API (http://jsonapi.org/) serializer.
Stars: ✭ 141 (+243.9%)
Mutual labels:  json-api, serializer
BarterOnly
An ecommerce platform to buy or exchange items at your convenience
Stars: ✭ 16 (-60.98%)
Mutual labels:  json-api, serializer
Jsonapi.rb
Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
Stars: ✭ 116 (+182.93%)
Mutual labels:  json-api, serializer
Dictfier
Python library to convert/serialize class instances(Objects) both flat and nested into a dictionary data structure. It's very useful in converting Python Objects into JSON format
Stars: ✭ 67 (+63.41%)
Mutual labels:  json-api, serializer
hanami-serializer
Serializer library for hanami applications
Stars: ✭ 22 (-46.34%)
Mutual labels:  json-api, serializer
Symfony Jsonapi
JSON API Transformer Bundle for Symfony 2 and Symfony 3
Stars: ✭ 114 (+178.05%)
Mutual labels:  json-api, serializer
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (+365.85%)
Mutual labels:  json-api, serializer
php-json-api
JSON API transformer outputting valid (PSR-7) API Responses.
Stars: ✭ 68 (+65.85%)
Mutual labels:  json-api, serializer
express-mquery
Expose mongoose query API through HTTP request.
Stars: ✭ 37 (-9.76%)
Mutual labels:  json-api
laravel-json-api
Integrate JSON:API resources on Laravel
Stars: ✭ 17 (-58.54%)
Mutual labels:  json-api
ds
👨‍🔬 In Russian: Обновляемая структурированная подборка бесплатных ресурсов по тематикам Data Science: курсы, книги, открытые данные, блоги и готовые решения.
Stars: ✭ 102 (+148.78%)
Mutual labels:  bookshelf
bookshelf-advanced-serialization
Plugin for Bookshelf.js supporting advanced serialization behavior
Stars: ✭ 17 (-58.54%)
Mutual labels:  bookshelf
oc-api-plugin
Base API Plugin for OctoberCMS
Stars: ✭ 26 (-36.59%)
Mutual labels:  serializer
laravel5-hal-json
Laravel 5 HAL+JSON API Transformer Package
Stars: ✭ 15 (-63.41%)
Mutual labels:  serializer
json-caching-proxy
Node caching HTTP proxy built on top of express-http-proxy. Persists requests and responses to an in-memory HAR-like data structure based on HAR1.2 . Caches JSON content-type responses by default with the ability to cache an entire site; including content-types describing images. Useful for testing front end code, mocking api, and saving the cac…
Stars: ✭ 31 (-24.39%)
Mutual labels:  json-api
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (+29.27%)
Mutual labels:  json-api
JsonFormatter
Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)
Stars: ✭ 26 (-36.59%)
Mutual labels:  serializer
playsonify
An opinionated micro-framework to help you build practical JSON APIs with Play Framework (or akka-http)
Stars: ✭ 42 (+2.44%)
Mutual labels:  json-api

JSON API Mapper

Build Status npm version david dm

JSON API Mapper (formerly Oh My JSON API) is a wrapper around @Seyz's excellent JSON API-compliant serializer, jsonapi-serializer, that removes the pain of generating the necessary options needed to serialize each of your ORM models.

Join the chat at https://gitter.im/scoutforpets/oh-my-jsonapi

Breaking Changes

This project has recently been renamed and rewritten using Typescript. While most functionality is generally the same, there have been a few deprecations and changes to how the Mapper is initialized. Please see the migration guide below.

How does it work?

A serializer requires some sort of 'template' to understand how to convert what you're passing in to whatever you want to come out. When you're dealing with an ORM, such as Bookshelf, it would be a real pain to have to generate the 'template' for every one of your Bookshelf models in order to convert them to JSON API. JSON API Mapper handles this by dynamically analyzing your models and automatically generating the necessary 'template' to pass to the serializer.

What ORMs do you support?

Initially, we only provide a mapper for Bookshelf. However, the library can be easily extended with new mappers to support other ORMs. PR's are more than welcome!

How do I install it?

npm install jsonapi-mapper --save

How do I use it?

It's pretty simple. You only need to configure the mapper and then use it as many times you need.

import Mapper = require('jsonapi-mapper');

// Create the mapper
var mapper = new Mapper.Bookshelf('https://api.hotapp.com');

// Use the mapper to output JSON API-compliant using your ORM-provided data
return mapper.map(myData, 'appointment');

How can I contribute?

God bless you if you're reading this! Check out our Contributing page

Migrating from OhMyJSONAPI

The migration process is painless:

  • Remove oh-my-jsonapi from your project.

  • Run npm install jsonapi-mapper --save

  • Convert any instances of the constructor:

    new OhMyJSONAPI('bookshelf', 'https://api.hotapp.com');

    to

    new Mapper.Bookshelf('https://api.hotapp.com');
  • Convert any instances of:

    jsonApi.toJSONAPI(myData, 'appointment');

    to

    mapper.map(myData, 'appointment');

API

new Mapper.Bookshelf(baseUrl, serializerOptions)
  • (optional) baseUrl (string): the base URL to be used in all links objects returned.
  • (optional) serializerOptions (string): options to be passed to the serializer. These options will override any options generated by the mapper. For more information on the raw serializer, please see the documentation here.
mapper#map(data, type, mapperOptions)
  • data (object): The data object from Bookshelf (either a Model or a Collection) to be serialized.
  • type (string): The type of the resource being returned. For example, if you passed in an Appointment model, your type might be appointment.
  • (optional) mapperOptions (object):
    • (optional) attributes (object):
      • (optional) omit (RegExp | string)[]: List of model attributes to omit from the resulting payload. For example, you may wish to exclude any foreign keys (as recommended by the JSON API-spec). Note: the model's idAttribute is automatically excluded by default.
      • (optional) include (RegExp | string)[]: List of model attributes to explicitly include from the resulting payload.
    • (optional) keyForAttr (function (string => string)): Function to customize the attributes keys. The function is passed as input the attribute key (string) and output the new attribute key (string).
    • (optional) relations (boolean | object): Flag to enable (true) or disable (false) serializing of related models on the response. Alternatively, you can provide an object containing the following options:
      • included (boolean | string[]) (default: true) - includes data for all relations in the response. You may optionally specify an array containing the names of specific relations to be included.
      • fields string[] - an array of relation names that should be included in the response.
    • (optional) typeForModel (object | function): To customize the type of a relation. If the value returned is falsy, then it's automatically pluralized. This function also affects the type passed as the second parameter of the map function.
      • object: The object should have the structure {"<relation-name>": "<type-to-use>"} (e.g. {"best-friend": "people"}).
      • function (string => string): The function is passed as input the relation name (string) and output the type for that relation (string) (e.g. (x) => x + '-resources').
    • (optional) enableLinks (boolean): Flag to enable (true) or disable (false) the generation of links in the payload. This may be useful if the consuming system doesn't take advantage of links and you want to save on payload size and maybe a bit of performance. Defaults to true.
    • (optional) query (object): An object containing the original query parameters. These will be appended to self and pagination links. Developer Note: This is not fully implemented yet, but following releases will fix that.
    • (optional) pagination (object): Pagination-related parameters for building pagination links for collections.
      • (required) offset (integer)
      • (required) limit (integer)
      • (optional) total or rowCount (integer)
    • (optional) meta (object): Top-level meta object to include in the document
    • (optional) outputVirtuals (boolean): Flag to include/omit the virtuals if the virtuals plugin is used, overrides the default outputVirtuals value.

How can I contribute?

The project is very open to collaboration from the public, especially on providing the groundwork for other ORM's (like Sequelize or Mongoose). Just open a PR!

The project source has been recently rewritten using Typescript, which has been proven useful for static checks and overall development.

Credits

  • Thanks to @Seyz. Without his work, the project would not be possible.
  • Thanks to the zomoz team (especially @ShadowManu) for their hard work in migrating the codebase to Typescript and writing a comprehensive test suite.
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].