Skip to main content

API Layer Pattern

Setiap feature module memiliki API layer yang terorganisir untuk menangani komunikasi HTTP dengan backend.

API Layer Structure

Standard CRUD Operations

Get List (Collection)

Get By ID (Single Item)

Create (POST)

Update (PUT/PATCH)

Delete

Barrel Export

Type Definitions

Custom API Functions

Import/Export

Stock Operations

Error Handling in API Layer

API with Caching

Using API in Store

Best Practices

  • Define types for request params
  • Define types for request body (DTOs)
  • Define types for response
  • Export types from feature module
  • API layer: Transform HTTP errors to meaningful messages
  • Store: Store error state for UI
  • Composable: Show toast/notification
  • Component: Display error UI

Next Steps

Data Flow

Complete data flow patterns

State Management

Pinia store patterns