Przejdź do treści
Biblioteka skilli
Programowanie · Planowanie

api-endpoint

/api-endpoint

Podpowiada reguły przy dodawaniu lub zmianie endpointu HTTP, zwłaszcza logowania i endpointów czytających lub zmieniających dane innych osób.

Repozytorium
backendskills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
09.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 09.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Podpowiada reguły przy dodawaniu lub zmianie endpointu HTTP, zwłaszcza logowania i endpointów czytających lub zmieniających dane innych osób.

Oryginalny opis (EN)

Rules for HTTP API endpoints. Use when adding or changing any endpoint (route, request or response shape, status codes), especially login and ones that read or change other users' data.

Jak działa

  1. 1. Check who may call it, not just that they're logged in
  2. 2. Bad input is a 4xx, never a 500
  3. 3. Limit how often anyone can try: login, codes, anything that sends or costs
  4. 4. Use what the repo already has, and test it
  5. Make it yours
Sekcje z nagłówków SKILL.md, w oryginale · 72 linii, 606 słów
Podgląd SKILL.md
---
name: api-endpoint
description: Rules for HTTP API endpoints. Use when adding or changing any endpoint (route, request or response shape, status codes), especially login and ones that read or change other users' data.
---

# API endpoint

Examples are TypeScript with `pg`. The rules apply to any stack.

Anything that changes money, stock or balances, or calls a payment provider or email: also follow the
`data-integrity` skill (transactions, locks, idempotency).

## 1. Check who may call it, not just that they're logged in

Why: a logged-in user who changes the id in the URL reads or edits someone else's data (IDOR).

```ts
// Bad: any logged-in user can read any invoice
const { rows } = await pool.query("select * from invoices where id = $1", [id]);

// Good: scope the query to the caller; someone else's invoice looks the same as a missing one
const { rows } = await pool.query("select * from invoices where id = $1 and account_id = $2", [id, user.accountId]);
if (rows.length === 0) return sendError(res, 404, "not_found", "Invoice not found");
```

Admins or other roles get access through an explicit role check, never by skipping the filter.

## 2. Bad input is a 4xx, never a 500

Why: a 500 on bad input hides real errors in the noise. Bad values that slip through (negative amounts,
fractions) corrupt data.

- Validate the body and path params at the edge: types, integers where money and quantities are counted,
  ranges (`quantity >= 1`, `amountCents > 0`), required fields, ids that aren't numbers.
- Handle what a request can legally contain but your code doesn't expect, like the same item listed
  twice. Merge the duplicates or reject them with a 400, but don't let the request crash into a 500.
- Map expected database errors: unique violation (`23505`) → 409, foreign key violation (`23503`) → 404 or 400.

## 3. Limit how often anyone can try: login, codes, anything that sends or costs

Why: without a limit, a script guesses passwords or one-time codes until one works, or sends thousands of
emails and SMS on your bill.

```ts
// Bad: counts a failure only after checking it; 50 parallel guesses all see "0 failures so far"
if (failures.get(email) >= 10) return sendError(res, 429, ...);
if (!(await verifyPassword(password, hash))) failures.set(email, failures.get(email) + 1);

// Good: count the try first, in one atomic statement, in storage every server shares
const { rows: [c] } = await pool.query(
  `insert into attempts (key, n, since) values ($1, 1, now())
   on conflict (key) do update set n = attempts.n + 1 returning n`, [`login:${email.toLowerCase()}`]);
if (c.n > 10) return sendError(res, 429, "too_many_attempts", "Try again later");
```

- Key the limit on the account (and on the IP, with a looser limit), and make the window expire.
- Once the limit is hit, refuse even the right password until the window ends.
- An unknown account and a wrong password get the same response, so nobody can find out which accounts exist.
- In-memory counters only work with one server. Use the database or Redis.

## 4. Use what the repo already has, and test it

Why: a second auth check, error format or DB helper drifts from the first, and reviewers have to catch it.

- Use the repo's auth, error format and database access. Errors never return a bare string or a stack trace.
- Add tests with the repo's test setup: the happy path, someone else's resource, and bad input.

## Make it yours

Your team's choices. The rules above stay the same.

- **API collection:** every new or changed endpoint goes into `postman/*.postman_collection.json` in
  the same change: method, URL with `{{baseUrl}}`, an example body, in the shape of the existing requests.
- **Error format:** `{ "error": { "code", "message" } }`.
- **Someone else's resource:** 404 (don't reveal it exists).

Wersje

RepozytoriumWynikLicencja
Ta strona · globalmpc/backendskills100MIT
proteanhq/protean100Apache-2.0
globalmpc/backendskills95MIT
event4u-app/agent-config90MIT

Migawka bazy z 13.11.2026 · wersja paczki 24bd00af19b3 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90add-api-endpoint
    Dodaje lub rozszerza endpoint HTTP lub API: nową trasę, handler albo metodę RPC z walidacją żądania i zdefiniowaną odpowiedzią.
  • 100api-designer
    Generuje gotowe do produkcji specyfikacje endpointów REST API dla dowolnego systemu lub domeny opisanej przez użytkownika.
  • 100api-design-rest
    Stosuje reguły projektowania endpointów HTTP: kształty żądań i odpowiedzi, kody, formaty błędów, stronicowanie, wersje i limity.
  • 100api-design
    Pomaga projektować, implementować i recenzować API HTTP: endpointy, kształt żądań i odpowiedzi, błędy, paginacja, wersjonowanie i autoryzacja.
  • 100add-endpoint
    Dodaje nowy endpoint HTTP do usługi dostępu, z modelami, zmianami w przechowywaniu i testami dla każdego kodu statusu.
  • 100api-design
    Projektuje czyste i spójne API HTTP/REST i JSON: zasoby i URL, metody, kody statusu, kształty żądań i odpowiedzi, paginacja, błędy, wersjonowanie i uwierzytelnianie.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.