Skip to content
On this page

createJsonMutation since v0.2

Formulae

createJsonMutation(config)

Config fields:

  • params?: parameters for the Mutation

    • You can declare Mutation parameters by call declareParams function.
    • If not passed, Mutation will be created without parameters.
  • request: declarative rules to formulate request to the API.

    • method: String
    • url: Sourced string
    • body: Sourced Json, any value which can be serialized to JSON and parsed back without loses by JavaScript native module JSON. For example, { a: 1, b: 2 }. Note that body cannot be used in GET and HEAD requests.
    • query?: Sourced object, keys of the object must be String and values must be String or Array<String> or (since v0.8) Sourced String containing ready-to-use query string
    • headers?: Sourced object, keys of the object must be String and values must be String or Array<String>
  • response: declarative rules to handle response from the API.

    • contract: Contract allows you to validate the response and decide how your application should treat it — as a success response or as a failed one.
    • validate?: Validator allows you to dynamically validate received data.
    • mapData?: optional mapper for the response data, available overloads:
      • ({ result, params }) => mapped
      • { source: Store, fn: ({ result, params }, source) => mapped }
    • status.expected: number or Array<number> of expected HTTP status codes, if the response status code is not in the list, the mutation will be treated as failed
  • concurrency?: concurrency settings for the Query

    • abort?: Event after calling which all in-flight requests will be aborted

Released under the MIT License.