class
JSONAPI::QueryParams
- JSONAPI::QueryParams
- Reference
- Object
Overview
Parses and validates JSON:API query parameters: include, fields[...], #sort,
filter[...], and page[...].
Defined in:
jsonapi/query_params.crConstructors
- .from_request(request : HTTP::Request) : QueryParams
- .new(includes : Array(String) = [] of String, fields : Hash(String, Array(String)) = Hash(String, Array(String)).new, sort : Array(SortField) = [] of SortField, filter : Hash(String, String) = Hash(String, String).new, page : Hash(String, String) = Hash(String, String).new)
- .parse(query : String | Nil) : QueryParams
- .parse(params : URI::Params) : QueryParams
Instance Method Summary
- #fields : Hash(String, Array(String))
- #fieldset_for(type : String) : Array(String) | Nil
- #filter : Hash(String, String)
- #include?(path : String) : Bool
- #includes : Array(String)
- #page : Hash(String, String)
- #page_cursor : String | Nil
- #page_number : Int32 | Nil
- #page_size : Int32 | Nil
- #sort : Array(SortField)
-
#validate!(allowed_includes : Enumerable(String) | Nil = nil, allowed_sorts : Enumerable(String) | Nil = nil, allowed_filters : Enumerable(String) | Nil = nil, allowed_fields : Hash(String, Array(String)) | Nil = nil) : self
Validates parsed parameters against endpoint allowlists, raising
QueryParamErrorwith spec-compliantsource.parameterpointers on any disallowed option.
Constructor Detail
def self.new(includes : Array(String) = [] of String, fields : Hash(String, Array(String)) = Hash(String, Array(String)).new, sort : Array(SortField) = [] of SortField, filter : Hash(String, String) = Hash(String, String).new, page : Hash(String, String) = Hash(String, String).new)
#
Instance Method Detail
def validate!(allowed_includes : Enumerable(String) | Nil = nil, allowed_sorts : Enumerable(String) | Nil = nil, allowed_filters : Enumerable(String) | Nil = nil, allowed_fields : Hash(String, Array(String)) | Nil = nil) : self
#
Validates parsed parameters against endpoint allowlists, raising QueryParamError
with spec-compliant source.parameter pointers on any disallowed option.