Table of Contents

The WebApi Helpers on the Sxc Controller - Bare Metal

you are here (click to zoom) - discover the stack

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...

  1. Get the correct URL for the endpoint
  2. 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:

  1. Simple api-urls like controller/method or controller/method?params will be converted to the full API needed
  2. Longer API urls like app/auto/controller/method will also be converted to the full url
  3. 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:

  1. ModuleId and PageId
  2. Security headers/tokens
  3. 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

  1. jQuery based webApi.get(...) etc. introduced in 2sxc 04.00 - see old docs
  2. fetchRaw(), fetchJson(), url(), headers() API introduced as beta in v12.10
  3. jQuery commands deprecated in v12.10 but will continue to work if the page has jQuery loaded
  4. url(...) enhanced with parameters object in v12.11
  5. fetchRaw(...) created to fix difficult naming in 12.10; fetch(...) is now deprecated and will stop working some day
  6. fetchRaw, fetchJson, sxc.data(...) and sxc.query(...) official for use 13.04