createJsonQuery
Formulae
createJsonQuery(config)
Config fields:
params?: parameters for the Query- You can declare Query parameters by call
declareParamsfunction. - If not passed, Query will be created without parameters.
- You can declare Query parameters by call
initialData?: initial data of the Query, will be passed to the$datastore as an initial valuerequest: declarative rules to formulate request to the API.method: Stringurl: Sourced stringbody: 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 inGETandHEADrequests.query?: Sourced object, keys of the object must beStringand values must beStringorArray<String>or (since v0.8) Sourced String containing ready-to-use query stringheaders?: Sourced object, keys of the object must beStringand values must beStringorArray<String>credentials?: since v0.7 String, available values:omit— do not include credentialssame-origin— include credentials only if the request URL is the same origininclude— include credentials on all requests
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:(res) => mapped{ source: Store, fn: (data, res) => mapped }
resobject contains:result: parsed and validated response dataparams: params which were passed to the Queryheaders: since v0.13 raw response headers
Showcases
- Real-world showcase with SolidJS around JSON API
- Real-world showcase with React around JSON API
- Real-world showcase with Forest around JSON API
Live demo
You can play around with the factory in the live demo below 👇