Skip to content

feat: export createApi from main module#1116

Open
taras wants to merge 1 commit intov4-1-alphafrom
feat/export-createapi
Open

feat: export createApi from main module#1116
taras wants to merge 1 commit intov4-1-alphafrom
feat/export-createapi

Conversation

@taras
Copy link
Member

@taras taras commented Feb 16, 2026

Summary

Export the createApi function from the main effection module so users can create APIs with middleware support without importing from experimental.ts.

Changes

  • Add comprehensive JSDoc documentation with examples for createApi
  • Export createApi from lib/mod.ts
  • Update test to import createApi from main module instead of experimental

Why

The createApi function enables:

  • Dependency injection: Swap implementations based on context
  • Test mocking: Replace real operations with test doubles
  • Instrumentation: Add logging, metrics, or tracing middleware

This is now stable enough to be part of the public API.

Usage

import { createApi, run } from "effection";

const myApi = createApi("myApi", {
  *fetch(url: string) {
    return yield* until(globalThis.fetch(url));
  }
});

// Use the API
await run(function*() {
  let response = yield* myApi.operations.fetch("/api/data");
});

// With middleware for testing
await run(function*() {
  yield* myApi.around({
    *fetch() {
      return { ok: true, json: () => ({ mocked: true }) };
    }
  });
  // All fetch calls now return mocked data
});

Notes

Once this PR is merged and the preview package is published, we can update the @effectionx/* packages to use createApi.

Export the createApi function from the main effection module so users
can create APIs with middleware support without importing from
experimental.ts.

- Add comprehensive JSDoc documentation with examples for createApi
- Update test to import createApi from main module
- Enables dependency injection, test mocking, and instrumentation

BREAKING: createApi is now part of the public API
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/thefrontside/effection@1116

commit: fb9d41d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant