blitz-js / blitz-js/legacy-framework

Custom API request helper function

Open
#38 2 comments 3 reactions 0 assignees View on GitHub
legacy-framework status/ready-to-define-implementation
Dominant language
JavaScript
Stars
3
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### What do you want and why?
Simplify requests to custom api routes that use blitz session middleware.

```ts
import { getAntiCSRFToken } from "blitz";

const antiCSRFToken = getAntiCSRFToken();

window.fetch("/api/custom", {
credentials: "include",
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json", "anti-csrf": antiCSRFToken },
});
```

### Possible implementation(s)

```ts
import { fetchWithCredentials } from 'blitz';

fetchWithCredentials("/api/custom", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
});
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing getAntiCSRFToken and the custom /api/custom request shown in the issue, then inspect the existing Blitz request helpers and exports. Done means a reusable fetchWithCredentials helper can simplify authenticated custom API requests while preserving credentials and anti-CSRF handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.