• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    Data REST and CRUD Web API

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

    2sxc provides a full set of REST endpoints for CRUD (Create, Read, Update, Delete) operations like:

    1. Read a list of all items/entities
    2. Read a single item/entity
    3. Create an item/entity
    4. Create an item/entity which is metadata for something
    5. Update an item/entity
    6. Delete an item/entity
    Tip

    Starting in 2sxc 11.10+ the admin-UI has built-in help to get started. These UIs also show sample code and everything. So you probably don't need to read the stuff here and just go ahead with that.

    Tip

    Starting with 2sxc v13, the data-api is .../app/.../data/TYPENAME.

    In previous versions, it's .../app/.../content/TYPENAME.

    JSON Data Format

    Read JSON Data Format used in WebAPI calls (technical) to understand the data format.

    Read Data-Items/Entities

    Assume you have the blog-app installed and your JS would request a JSON from this endpoint (logged in as SystemAdmin, so security is not an issue):

    [root-path]/app/auto/data/BlogPost

    ...then your JS would receive a JSON with all BlogPost items.

    Reading [root-path]/app/auto/data/BlogPost/1050 would give you exactly one BlogPost item (with the id 1050)

    Tip

    To figure out the exact path and the [root-path] part, best read about it in the admin-ui or work your way into the URLs for 2sxc WebAPI and REST APIs

    Create Data-Items/Entities

    Doing an http POST to this [root-path]/app/auto/data/BlogPost with a POST body of { "Title": "changed title"} would let you create the item. You will get a return message containing ID, GUID etc. of the new item.

    If your POST package also contains a EntityGuid then this will be used as the GUID for the new item.

    Update Data-Items/Entities

    Doing an http POST to this [root-path]/app/auto/data/BlogPost/1050 with a POST body of { "Title": "changed title"} would let you update the item 1050.

    Delete Data-Items/Entities

    Doing an http DELETE to this [root-path]/app/auto/data/BlogPost/1050 would delete the item 1050.

    JavaScript Helpers

    The $2sxc and the sxc Controller make it really easy to use this. Best to get familiar with them.

    About Security / Permissions

    Warning

    You are usually developing as a super-user, in which case these endpoints automatically work. If you want normal users to do certain things like create items, you need to configure the permissions.

    To use these endpoints for normal users, you would need to enable the permissions and then you can access them using the REST URLs.

    1. reading data requires read-permissions on that content-type
    2. writing data requires write-permissions or a content-type or on a specific item (owner-permissions)

    Use this Checklist to get started:

    Recommended Reading

    • General WebApi Specs
    • URL Schema

    History

    1. Introduced Data-REST API in 2sxc 5.x but on a .../content... endpoint
    2. Added in-admin help to access it in 11.10
    3. Improved url to data to be .../data/... instead of the previous .../content/... in v13
    • Improve this Doc
    Back to top Generated by DocFX