Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.96 KB

File metadata and controls

49 lines (36 loc) · 1.96 KB
sidebar_position 2

import StackBlitzGithub from '@site/src/components/StackBlitzGithub';

Server Adapter

Overview

Server adapters are components that handle the integration with specific frameworks. They understand how to install API routes and handle framework-specific request and response objects.

Server adapters need to be configured with an API handler that defines the API specification. The following diagram illustrates the relationship between them:

flowchart TD
    framework["`Web Framework
    _Next.js, Express, etc._`"]
    adapter[Server Adapter]
    api[API Handler]
    zenstack[ZenStack ORM]
    framework -->|Request/Response| adapter
    adapter -->|Framework Agnostic Request/Response| api
    api -->|ORM Queries| zenstack
Loading

Example

Let's use a real example to see how API handlers and server adapters work together to serve an automatic secured data query API. A few notes about the example:

  • Express.js is used to demonstrate, but the same concept applies to other supported frameworks.
  • Authentication is simulated by using the "x-userid" header. In real applications, you would use a proper authentication mechanism.
  • ZModel schema is configured with access policies.
  • For each request, the getClient call back is called to get an ORM client instance bound to the current user.

Catalog

ZenStack currently maintains the following server adapters. New ones will be added over time based on popularity of frameworks.