> ## Documentation Index
> Fetch the complete documentation index at: https://build.onswig.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Server Route Adapters

The Developer SDK includes server adapters for applications that want a fixed
route surface without repeating request parsing. These adapters never run in a
browser and do not include a browser client.

<Warning>
  Mount these routes only behind application authentication, authorization,
  validation, and rate limiting. The adapter protects the Swig API key from the
  response body; it does not decide who may use your application route.
</Warning>

## Next.js

```typescript theme={null}
// app/api/swig/[...swig]/route.ts
import { createSwigRouteHandlers } from '@swig-wallet/developer-sdk/next';
import { requireSwigAccess } from '@/lib/server/auth';

const swigHandlers = createSwigRouteHandlers({
  apiKey: process.env.SWIG_API_KEY,
  network: 'devnet',
  feePayer: process.env.SWIG_FEE_PAYER,
});

export async function GET(request: Request) {
  await requireSwigAccess(request);
  return swigHandlers.GET(request);
}

export async function POST(request: Request) {
  await requireSwigAccess(request);
  return swigHandlers.POST(request);
}
```

`requireSwigAccess` represents your application's server-side session and
authorization check. It must reject the request before the SDK handler runs.

## NestJS

```typescript theme={null}
import { All, Controller, Req, Res, UseGuards } from '@nestjs/common';
import { createSwigNestHandler } from '@swig-wallet/developer-sdk/nest';
import type { Request, Response } from 'express';

const swigHandler = createSwigNestHandler();

@Controller('internal/swig')
@UseGuards(ApplicationAuthGuard)
export class SwigController {
  @All('*')
  handle(@Req() request: Request, @Res() response: Response) {
    return swigHandler(request, response);
  }
}
```

## Any Fetch server

```typescript theme={null}
import {
  createSwigFetchHandler,
  createSwigGetHandler,
} from '@swig-wallet/developer-sdk/server/fetch';
```

Both framework adapters wrap these `Request`/`Response` handlers.

## Python

```python theme={null}
from swig_developer_sdk import SwigProxyConfig, create_swig_proxy_handler

handler = create_swig_proxy_handler(
    SwigProxyConfig(api_key=swig_api_key, network="devnet")
)

response = await handler.handle(
    method="POST",
    path="/transfer/sol",
    body=request_body,
)
```

Adapt `response.status` and `response.body` at the authenticated framework
boundary.

## Routes

Preparation:

```text theme={null}
POST /wallet/create
POST /prepare
POST /transfer/sol
POST /transfer/spl-token
POST /swap/jupiter
```

Reads:

```text theme={null}
GET  /wallet/:swigConfigAddress/balance/usd
GET  /wallet/:swigConfigAddress/token-balances
GET  /wallet/:swigConfigAddress/token-transactions
GET  /wallet/:swigConfigAddress/roles
GET  /paymaster/balance
```

Ramp:

```text theme={null}
GET  /ramp/onramp/options
POST /ramp/onramp/quote
POST /ramp/onramp/session
GET  /ramp/onramp/session/:sessionId
GET  /ramp/offramp/options
POST /ramp/offramp/quote
POST /ramp/offramp/session
POST /ramp/offramp/session/:sessionId/prepare
POST /ramp/offramp/session/:sessionId/submit
GET  /ramp/offramp/session/:sessionId
```

Preparation routes return unsigned prepared data. The adapter does not sign
transactions; the optional signing utilities are a separate, no-API-key
surface. Sponsorship is intentionally not exposed by the adapter; call
`swig.transactions.sponsor(...)` explicitly from trusted server code after
your application returns a signed transaction.

## Requester resolution

If requester authority comes from authenticated role context, resolve it on
the server:

```typescript theme={null}
createSwigRouteHandlers({
  resolveRequesterAuthority: async ({ wallet }) => {
    return lookupRequesterForRole(wallet?.roleId);
  },
});
```

Validate that the caller may act for the resolved authority before returning
it. `feePayer` accepts the same function form when payer selection depends on
the authenticated caller.
