<commit_before># Sinja (Sinatra::JSONAPI)

<!--
  Title: Sinja
  Description: RESTful, {json:api}-compliant web services in Sinatra
  Author: <NAME>
  Keywords: JSON, API, JSONAPI, JSON:API, {json:api}, Ruby, Sinatra, JSONAPI::Serializers, jsonapi-serializers
  -->

[![Gem Version](https://badge.fury.io/rb/sinja.svg)](https://badge.fury.io/rb/sinja)
[![Dependency Status](https://gemnasium.com/badges/github.com/mwpastore/sinja.svg)](https://gemnasium.com/github.com/mwpastore/sinja)
[![Build Status](https://travis-ci.org/mwpastore/sinja.svg?branch=master)](https://travis-ci.org/mwpastore/sinja)
[![{json:api} version](https://img.shields.io/badge/%7Bjson%3Aapi%7D%20version-1.0-lightgrey.svg)][7]
[![Chat in #sinja-rb on Gitter](https://badges.gitter.im/sinja-rb/Lobby.svg)](https://gitter.im/sinja-rb/Lobby)

Sinja is a [Sinatra 2.0][1] [extension][10] for quickly building [RESTful][11],
[{json:api}][2]-compliant web services, leveraging the excellent
[JSONAPI::Serializers][3] gem for payload serialization. It enhances Sinatra's
DSL to enable resource-, relationship-, and role-centric API development, and
it configures Sinatra with the proper settings, MIME-types, filters,
conditions, and error-handling.

There are [many][31] parsing (deserializing), rendering (serializing), and
other "JSON API" libraries available for Ruby, but relatively few that attempt
to correctly implement the entire {json:api} server specification, including
routing, request header and query parameter checking, and relationship
side-loading.  Sinja lets you focus on the business logic of your applications
without worrying about the specification, and without pulling in a heavy
framework like [Rails][16]. It's lightweight, ORM-agnostic, and
[Ember.js][32]-friendly!

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Synopsis](#synopsis)
- [Installation](#installation)
- [Ol' Blue Eyes is Back](#ol-blue-eyes-is-back)
- [Basic Usage](#basic-usage)
  - [Configuration](#configuration)
    - [Sinatra](#sinatra)
    - [Sinja](#sinja)
  - [Resource Locators](#resource-locators)
  - [Action Helpers](#action-helpers)
    - [`resource`](#resource)
    - [`has_one`](#has_one)
    - [`has_many`](#has_many)
- [Advanced Usage](#advanced-usage)
  - [Action Helper Hooks & Utilities](#action-helper-hooks--utilities)
  - [Authorization](#authorization)
    - [`default_roles` configurables](#default_roles-configurables)
    - [`:roles` Action Helper option](#roles-action-helper-option)
    - [`role` helper](#role-helper)
  - [Query Parameters](#query-parameters)
  - [Working with Collections](#working-with-collections)
    - [Filtering](#filtering)
    - [Sorting](#sorting)
    - [Paging](#paging)
    - [Finalizing](#finalizing)
  - [Conflicts](#conflicts)
  - [Validations](#validations)
  - [Missing Records](#missing-records)
  - [Transactions](#transactions)
  - [Side-Unloading Related Resources](#side-unloading-related-resources)
  - [Side-Loading Relationships](#side-loading-relationships)
    - [Avoiding Null Foreign Keys](#avoiding-null-foreign-keys)
  - [Coalesced Find Requests](#coalesced-find-requests)
  - [Patchless Clients](#patchless-clients)
- [Extensions](#extensions)
  - [Sequel](#sequel)
- [Application Concerns](#application-concerns)
  - [Performance](#performance)
  - [Public APIs](#public-apis)
    - [Commonly Used](#commonly-used)<commit_msg>Update TOC in README<commit_after># Sinja (Sinatra::JSONAPI)

<!--
  Title: Sinja
  Description: RESTful, {json:api}-compliant web services in Sinatra
  Author: <NAME>
  Keywords: JSON, API, JSONAPI, JSON:API, {json:api}, Ruby, Sinatra, JSONAPI::Serializers, jsonapi-serializers
  -->

[![Gem Version](https://badge.fury.io/rb/sinja.svg)](https://badge.fury.io/rb/sinja)
[![Dependency Status](https://gemnasium.com/badges/github.com/mwpastore/sinja.svg)](https://gemnasium.com/github.com/mwpastore/sinja)
[![Build Status](https://travis-ci.org/mwpastore/sinja.svg?branch=master)](https://travis-ci.org/mwpastore/sinja)
[![{json:api} version](https://img.shields.io/badge/%7Bjson%3Aapi%7D%20version-1.0-lightgrey.svg)][7]
[![Chat in #sinja-rb on Gitter](https://badges.gitter.im/sinja-rb/Lobby.svg)](https://gitter.im/sinja-rb/Lobby)

Sinja is a [Sinatra 2.0][1] [extension][10] for quickly building [RESTful][11],
[{json:api}][2]-compliant web services, leveraging the excellent
[JSONAPI::Serializers][3] gem for payload serialization. It enhances Sinatra's
DSL to enable resource-, relationship-, and role-centric API development, and
it configures Sinatra with the proper settings, MIME-types, filters,
conditions, and error-handling.

There are [many][31] parsing (deserializing), rendering (serializing), and
other "JSON API" libraries available for Ruby, but relatively few that attempt
to correctly implement the entire {json:api} server specification, including
routing, request header and query parameter checking, and relationship
side-loading.  Sinja lets you focus on the business logic of your applications
without worrying about the specification, and without pulling in a heavy
framework like [Rails][16]. It's lightweight, ORM-agnostic, and
[Ember.js][32]-friendly!

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Synopsis](#synopsis)
- [Installation](#installation)
- [Ol' Blue Eyes is Back](#ol-blue-eyes-is-back)
- [Basic Usage](#basic-usage)
  - [Configuration](#configuration)
    - [Sinatra](#sinatra)
    - [Sinja](#sinja)
  - [Resources](#resources)
  - [Resource Locators](#resource-locators)
  - [Action Helpers](#action-helpers)
    - [`resource`](#resource)
    - [`has_one`](#has_one)
    - [`has_many`](#has_many)
- [Advanced Usage](#advanced-usage)
  - [Action Helper Hooks & Utilities](#action-helper-hooks--utilities)
  - [Authorization](#authorization)
    - [`default_roles` configurables](#default_roles-configurables)
    - [`:roles` Action Helper option](#roles-action-helper-option)
    - [`role` helper](#role-helper)
  - [Query Parameters](#query-parameters)
  - [Working with Collections](#working-with-collections)
    - [Filtering](#filtering)
    - [Sorting](#sorting)
    - [Paging](#paging)
    - [Finalizing](#finalizing)
  - [Conflicts](#conflicts)
  - [Validations](#validations)
  - [Missing Records](#missing-records)
  - [Transactions](#transactions)
  - [Side-Unloading Related Resources](#side-unloading-related-resources)
  - [Side-Loading Relationships](#side-loading-relationships)
    - [Deferring Relationships](#deferring-relationships)
    - [Avoiding Null Foreign Keys](#avoiding-null-foreign-keys)
  - [Coalesced Find Requests](#coalesced-find-requests)
  - [Patchless Clients](#patchless-clients)
- [Extensions](#extensions)
  - [Sequel](#sequel)
- [Application Concerns](#application-concerns)
  - [Performance](#performance)
  - [Public APIs](#public-apis)
    - [Commonly Used](#commonly-used)
{'fraction_non_alphanumeric': 0.16010796988208553, 'fraction_numerical': 0.006535019178860633, 'mean_word_length': 5.058519793459553, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5138181', 'n_tokens_mistral': 2430, 'n_tokens_neox': 2241, 'n_words': 493}