Edit

Share via


How to call REST endpoints

Data API builder (DAB) provides a RESTful web API that lets you access tables, views, and stored procedures from a connected database. Each exposed database object is defined as an entity in the runtime configuration.

By default, DAB hosts REST endpoints at:

https://{base_url}/api/{entity}

Note

All path components and query parameters are case sensitive.

Keywords supported in Data API builder

Concept REST Purpose
Projection $select Choose which fields to return
Filtering $filter Restrict rows by condition
Sorting $orderby Define the sort order
Page size $first Limit the items per page
Continuation $after Continue from the last page

Basic structure

To call a REST API, construct a request using this pattern:

{HTTP method} https://{base_url}/{rest-path}/{entity}

Example reading all records from the book entity:

GET https://localhost:5001/api/book

The response is a JSON object with a value array. Pagination and error information appear only when applicable.

Note

By default, DAB returns up to 100 items per query unless configured otherwise (runtime.pagination.default-page-size).

GET https://localhost:5001/api/book

Success:

{
  "value": [
    { "id": 1, "title": "Dune", "year": 1965, "pages": 412 },
    { "id": 2, "title": "Foundation", "year": 1951, "pages": 255 }
  ]
}

Success with pagination:

{
  "value": [
    { "id": 1, "title": "Dune", "year": 1965, "pages": 412 },
    { "id": 2, "title": "Foundation", "year": 1951, "pages": 255 }
  ],
  "nextLink": "https://localhost:5001/api/book?$after=WyJCb29rMiJd"
}

Error:

{
  "error": {
    "code": "NotFound",
    "message": "Could not find item with the given key.",
    "status": 404
  }
}

Query types

Each REST entity supports both collection and single-record reads.

Operation Description
GET /api/{entity} Returns a list of records
GET /api/{entity}/{primary-key-column}/{primary-key-value} Returns one record by primary key

Example returning one record:

GET /api/book/id/1010

Example returning many:

GET /api/book

Filtering results

Use the $filter query parameter to restrict which records are returned.

GET /api/book?$filter=title eq 'Foundation'

This query returns all books whose title equals "Foundation."

Filters can include logical operators for more complex queries:

GET /api/book?$filter=year ge 1970 or title eq 'Dune'

For more information, see the $filter argument reference.

Sorting results

The $orderby parameter defines how records are sorted.

GET /api/book?$orderby=year desc, title asc

This returns books ordered by year descending, then by title.

For more information, see the $orderby argument reference.

Limiting results {#first-and-after}

The $first parameter limits how many records are returned in one request.

GET /api/book?$first=5

This returns the first five books, ordered by primary key by default. You can also use $first=-1 to request the configured maximum page size.

For more information, see the $first argument reference.

Continuing results

To fetch the next page, use $after with the continuation token from the previous response.

GET /api/book?$first=5&$after={continuation-token}

The $after token identifies where the last query ended. For more information, see the $after argument reference.

Field selection (projection)

Use $select to control which fields are included in the response.

GET /api/book?$select=id,title,price

This returns only the specified columns. If a field is missing or not accessible, DAB returns 400 Bad Request.

For more information, see the $select argument reference.

Modifying data

The REST API also supports create, update, and delete operations depending on entity permissions.

Method Action
POST Create a new item
PUT Replace an existing item (or create if missing)
PATCH Update an existing item (or create if missing)
DELETE Remove an item by primary key

Create a new record

Use POST to create a new item.

POST https://localhost:5001/api/book
Content-Type: application/json

{
  "id": 2000,
  "title": "Leviathan Wakes",
  "year": 2011,
  "pages": 577
}

Update an existing record

Use PATCH to update specific fields on an existing item.

PATCH https://localhost:5001/api/book/id/2000
Content-Type: application/json

{
  "id": 2000,
  "title": "Leviathan Wakes",
  "year": 2011,
  "pages": 577
}

Delete a record

Use DELETE to remove an item by primary key.

DELETE https://localhost:5001/api/book/id/2000