Skip to content

Parse JSON API endpoint and its query parameters to a usable Hash

License

Notifications You must be signed in to change notification settings

g13ydson/json_api_query_parser

Repository files navigation

JSON API query parser

Gem Version Build Status Maintainability Test Coverage

To be used for ruby projects that make use of JSON API

Installation

$ gem install json_api_query_parser

Or in the gemfile of the rails project

gem 'json_api_query_parser'

Usage

Require the gem 'json_api_query_parser' into your application and use the 'parse_request' method to convert the request.url to an easy usable Hash.

require('json_api_query_parser')
JsonApiQueryParser.parse_request("movies/5?include=actors,actors.agency&fields[movies]=title,year&fields[actors]=name&page[limit]=20")

Return data information

The Hash returned by the JsonApiQueryParser.parse_request will always be the same structure.

{
  :resource_type=>"movies", 
  :identifier=>"5", 
  :query_data=>{
    :include=>["actors", "actors.agency"], 
    :fields=>{:movies=>["title", "year"], :actors=>["name"]},
    :page=>{"limit"=>"20"}
  }
} 

About

Parse JSON API endpoint and its query parameters to a usable Hash

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published