Data API builder (DAB) provides REST and GraphQL endpoints over SQL Server, Azure Cosmos DB, PostgreSQL, MySQL, and SQL Data Warehouse. REST endpoints support several HTTP headers that let you control how requests behave. These headers give you precision over updates, caching, and discovering new resources.
If-Match
By default, DAB treats PUT
and PATCH
as upserts: update if the row exists, insert if not. Sometimes you need stricter semantics. If-Match
provides update-only behavior.
If-Match
in DAB only supports *
. Any other value is rejected.
Header value | Behavior |
---|---|
If-Match: * |
Update only if the row exists; otherwise 404 Not Found . |
Absent | Default upsert (insert if missing, update if found). |
Anything else | Rejected with 400 Bad Request . |
Example request that only updates if the row exists:
If the record exists, you get 200 OK
. If not, you get 404 Not Found
. This applies to both PUT
and PATCH
. DAB does not support ETag comparisons or concurrency tokens.
Read the documentation on If-Match.
Cache-Control
DAB can cache query results in memory or in a distributed cache. The Cache-Control
request header lets you override cache behavior. This applies only to DAB’s cache, not browsers or CDNs.
Directive | Behavior |
---|---|
no-cache |
Always query DB and refresh the cache. |
no-store |
Return cache if present; otherwise query DB but don’t store. |
only-if-cached |
Return cached result only, else 504 Gateway Timeout . |
Absent | Default: return cache if present, else query and cache. |
Request example using no-cache
.
GET /api/Books
Cache-Control: no-cache
Accept: application/json
Read the documentation on Cache headers.
Location
When you create a resource with POST
, DAB includes a Location
header showing the path of the new record. For PUT
or PATCH
that insert rows, it may be omitted.
POST
inserts:201 Created
withLocation
.PUT
/PATCH
updates:200 OK
, noLocation
.PUT
/PATCH
inserts:201 Created
,Location
may be omitted.
After creating a book with POST
, you will see Location
: id/123
. Clients can then immediately fetch /api/Books/id/123
.
Example POST response:
HTTP/1.1 201 Created
Location: id/123
Content-Type: application/json
{
"id": 123,
"title": "New Book"
}
Read the documentation on Location.
Summary
Use If-Match
for strict updates, Cache-Control
to tune caching, and Location
to discover new resources. Together, these headers make your APIs predictable and reliable.
0 comments
Be the first to start the discussion.