The WebApi Helpers on the Sxc Controller - Bare Metal
In most cases you will want to use the new fetch APIs in 2sxc 12.10+.
But there are cases where you want to create your own calls using
Axios,
jQuery,
SuperAgent,
Angular HttpClient
or whatever API system you want.
In these cases, you just need some help to...
- Get the correct URL for the endpoint
- Probably get all the headers you need for the security tokens
This is what the Bare Metal APIs are for.
Bare Metal APIs
These APIs get you things you need to construct your own fetch
, Request
, XHR XMLHttpRequest
or any of the above framework are these:
webApi.url(url, params?)
webApi.headers(verb?)
webApi.url(...)
This method will extend short API / Content / Query URLs for you. This means it will handle URLs like this:
- Simple api-urls like
controller/method
orcontroller/method?params
will be converted to the full API needed - Longer API urls like
app/auto/controller/method
will also be converted to the full url - Parameters in the object
params
will be added as?...=...
v12.11+
webApi.headers(verb?)
This will get you an object containing all the headers you need for a common WebAPI request. It includes things like:
ModuleId
andPageId
- Security headers/tokens
- Encoding headers - this will vary based on the optional verb you pass in
If you don't specify a verb, GET
is assumed, so it will only have encoding-headers for the response.
History
- jQuery based
webApi.get(...)
etc. introduced in 2sxc 04.00 - see old docs fetchRaw()
,fetchJson()
,url()
,headers()
API introduced as beta in v12.10- jQuery commands deprecated in v12.10 but will continue to work if the page has jQuery loaded
url(...)
enhanced with parameters object in v12.11fetchRaw(...)
created to fix difficult naming in 12.10;fetch(...)
is now deprecated and will stop working some dayfetchRaw
,fetchJson
,sxc.data(...)
andsxc.query(...)
official for use 13.04