Class RequestBuilderImplInternal

RequestBuilderImpl

Description

Default implementation of the RequestBuilder interface

See

RequestBuilder - RequestBuilderImpl interface

Hierarchy

  • RequestBuilderImpl

Implements

Constructors

Properties - ODataOptions

Properties - Other

Methods - Advanced/Development functions

Methods - OData functions

Methods - Other

Methods - Resolve functions

Methods - Special functions

Constructors

Properties - ODataOptions

_count?: boolean = false

Whether to count the amount of results

_expand?: string[][] = []

The attributes to select

_filter?: string[][] = []

The attributes to filter by

_format?: "none" | "minimal" | "full"

The format to return the results in

_orderby?: string[]

The order to sort the results by

_select: string[] = []

The attributes to select

_skip?: number

Amount of results to skip

_top?: number

Amount of results to return

Properties - Other

_custom?: string

Custom query option

_endpoint: string = 'https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0'

Endpoint to make the request to

Default

"https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0"
_entity: string

Entity to make the request for

_id?: string

Unique id of the entity

Methods - Advanced/Development functions

Methods - OData functions

  • Expand the request to include information from other entities

    Parameters

    • attribute: string

      The attribute to expand

    • Optional func: string

      The function to apply to the attribute

    Returns RequestBuilder

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    .expand('FractieZetel')
    .expand('Stemming', '$select=Soort')

    Example

    new ODataRequest('Fractie')
    .expand('FractieZetel')
    // Multiple functions can be applied to the same expansion
    // Using a semicolon (;) to separate them
    .expand('Stemming', "$top=1 ; $select=Soort")
  • The amount of metadata to return with the results

    Parameters

    • format: "none" | "minimal" | "full"

      The format to use

    Returns RequestBuilder

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    .format('none')

    Example

    new ODataRequest('Fractie')
    .format('minimal')

    Example

    new ODataRequest('Fractie')
    .format('full')
  • Order the results by a specific attribute

    Parameters

    • field: string

      The attribute to order by

    • direction: "asc" | "desc" = 'asc'

      The direction to order by (asc or desc)

    Returns RequestBuilder

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    .orderby('NaamNL') // Direction defaults to asc

    Example

    new ODataRequest('Fractie')
    .orderby('NaamNL', 'asc')

    Example

    new ODataRequest('Fractie')
    .orderby('NaamNL', 'desc')
  • Select a specific attribute to return Will only show the attribute(s) selected for the entity

    Parameters

    • attribute: string

      The attribute to select

    Returns RequestBuilder

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    // You can select multiple attributes
    .select('NaamNL')
    .select('NaamEN')

    Example

    new ODataRequest('Fractie')
    .select('NaamNL')
  • Limit the amount of results returned

    Parameters

    • top: number

      The amount of results to return (1..250)

    Returns RequestBuilder

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    .top(1)

    Example

    new ODataRequest('Fractie')
    .top(250)

    Throws

    Error if $Top is already defined

    Throws

    Error if $Top is less than or equal to 0

    Throws

    Error if $Top is greater than 250

Methods - Other

  • Use a custom query. Will overwrite all previously declared functions. And will directly use the given query. Functions declared after this function will also be ignored.

    Parameters

    • query: string

      The custom query to use

    Returns RequestBuilder

    The RequestBuilderImpl

    Throws

    Error if the query does not start with a '$'

    Remarks

    • Will ignore all previously declared functions
    • Will ignore all functions declared after this function

    Example

    new ODataRequest('Fractie')
    .custom('$select=Afkorting')
    // https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie?$select=Afkorting

    Example

    new ODataRequest('Fractie')
    .custom('$select=Afkorting&$top=1')
    // https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie?$select=Afkorting&$top=1
  • Select multiple attributes to return Will only show the attribute(s) selected for the entity

    Parameters

    • attributes: string[]

      The attributes to select

    Returns RequestBuilderImpl

    The RequestBuilderImpl

    Example

    new ODataRequest('Fractie')
    .selectMultiple(['NaamNL', 'NaamEN'])
    // You can also use the select function multiple times
    .selectMultiple(['DatumActief', 'DatumInactief'])

    Example

    new ODataRequest('Fractie')
    .selectMultiple(['NaamNL', 'NaamEN'])
    // You can also use the selectMultiple function in combination with the select function
    .select('DatumActief')

Methods - Resolve functions

  • Given the current state of the RequestBuilderImpl, build the request url according to functions provided

    Returns string

    The build request url

    Example

    const construction = new ODataRequest('Fractie')
    .expand('FractieZetel')
    .top(1)

    // Log the request url (build)
    console.log(construction.build());
  • Given the current state of the RequestBuilderImpl, build the request url according to functions provided and then utilize cross-fetch to make the request

    Returns Promise<any>

    The response from the request

    See

    cross-fetch - Fetch API implementation

    Remarks

    Function flow: request -> build -> fetch

    Example

    new ODataRequest('Fractie')
    .expand('FractieZetel')
    .expand('Stemming', '$select=Soort')
    .top(1)
    .request()
    // Log the data
    .then(data => console.log(data))
    .catch(err => console.warn(err))

    Example

    const construction = new ODataRequest('Fractie')
    .expand('FractieZetel')
    .expand('Stemming', '$select=Soort')
    .top(1)

    construction.request().then((data) => {
    // Log the data
    console.log(data);
    }).catch((error) => {
    console.warn(error);
    });

Methods - Special functions

  • Experimental

    Unique function to gather information on a specific entity instead of the entire collection

    Parameters

    • id: string

      The unique id of the entity

    Returns RequestBuilder

    The RequestBuilderImpl

    Throws

    If invalid query options are provided

    Remarks

    [!] Does not work with all other functions Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.

    Example

    new ODataRequest('Fractie')
    .findById('65129918-f256-4975-9da4-488da34d6695')

Generated using TypeDoc