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
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
XMLHttpRequest or any of the above framework are these:
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?paramswill be converted to the full API needed
- Longer API urls like
app/auto/controller/methodwill also be converted to the full url
- Parameters in the object
paramswill be added as
This will get you an object containing all the headers you need for a common WebAPI request. It includes things like:
- 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.
- jQuery based
webApi.get(...)etc. introduced in 2sxc 04.00 - see old docs
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.11
fetchRaw(...)created to fix difficult naming in 12.10;
fetch(...)is now deprecated and will stop working some day
sxc.query(...)official for use 13.04