Table of Contents

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

2sxc Web API

2sxc has a fully featured WebApi for use in JavaScript or as Headless CMS. So you can call HTTP GET to an endpoint like app/News/data/NewsItems/ and get a list of news items.

You can also create / modify data using REST, access Queries and work with your custom Web-APIs - across all 2sxc platforms (Dnn / Oqtane / Custom) and with the security you need.

Simple Example

Here's an example JavaScript which would run in a 2sxc News-App on a Dnn page:

// Get news as a promise
var allNewsPromise = sxc.webApi.get('app/auto/data/News/');

// now log to console
allNewsPromise.then(data => console.log(data));

This example has some magic happening in the background. Specifically 3 important things happen on the client before sending:

  1. The real URL which is requested is a bit longer, but the webApi takes care of that.
  2. The server needs to know what App and Module the script is calling from. This Context information is also added by the webApi.
  3. To add security, a crypto-token is added which will prove that the JavaScript requesting this is running on the page. This is also added by webApi.

When the server receives the request, it too does important stuff.

  1. First it will use the URL and Context information to figure out what Site, Language and App should be accessed.
  2. The server will do some security checks to see if this request should be answered.
  3. Then it returns the data in a simple JSON format

Get Started Step 1: Decide which Endpoint you need

This checklist should help you decide:

Getting Started

Your 1-2-3 steps for using data endpoints are:

  1. Decide which endpoint you need
  2. Create / Publish the endpoint
    1. For standard endpoints, set the permissions as you need them
    2. For custom endpoints, write the C# code
  3. Write the code to read the data (typically in JavaScript)

Conventions Used

  • REST means that there is a url convention to access data like .../blogposts/25
  • REST also specifies that an HTTP GET is for reading, HTTP POST is for writing, etc.
  • All the APIs use JSON for sending/receiving data. This is the default schema.

You should find some code examples in this demo App

History

  1. Introduced Content-REST API in 2sxc 5.x
  2. Query added in 2sxc 8.10
  3. Enhanced with Polymorph Editions in 2sxc 9.35 (allowing subfolder/api)