# Api

```ts
interface Api<A>
```

A set of methods and values that can be decorated on a per-scope
basis. Apis are ideal for situations that require context
sensitivity such as dependency injection, test mocking, and
instrumentation.

### Examples
#### Example 1
```ts
import { type Operation } from "effection";
import { createApi } from "effection/experimental";

interface DbApi {
  query(sql: string): Operation<{ id: number; title: string }[]>;
}

let DatabaseApi = createApi<DbApi>("database", {
  *query(sql) {
    console.log("running", sql);
    return [];
  },
});

// scope-local decoration: logging, metrics, retries, mocks, etc.
yield* DatabaseApi.around({
  *query(args, next) {
    let [sql] = args;
    console.log("SQL:", sql);
    return yield* next(...args);
  },
});

let rows = yield* DatabaseApi.operations.query("select * from posts");
console.log(rows.length);
```

---


### Type Parameters
A
core shape of the Api


### Properties
<dl>
<dt class="border-dotted dark:border-blue-900 [&:not(:first-child)]:border-t-1 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2">**operations**: [K in keyof A]: A[K] extends [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;unknown&gt; ? A[K] : A[K] extends (...**args**:  ) =>  ? TReturn extends [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;unknown&gt; ? A[K] : (...**args**:  TArgs) => [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;TReturn&gt; : [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;A[K]&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3">
Every member of `A` "lifted" into an operation that invokes that
member on the current {Scope}
</dd>
<dt class="border-dotted dark:border-blue-900 [&:not(:first-child)]:border-t-1 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2">**around**: (**middlewares**: Partial&lt;[Around](https://frontside.com/effection/api/v4-next/Around.md)&lt;A&gt;&gt;, **options**<span class="inline-block bg-sky-100 rounded px-2 text-sm text-sky-900 mx-1">optional</span>: &#123;&#125;) => [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;void&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3">
Enhance an [Api](https://frontside.com/effection/api/v4-next/Api.md) within this scope by surrounding it with
middleware.

</dd>
<dt class="border-dotted dark:border-blue-900 [&:not(:first-child)]:border-t-1 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2">**invoke**: &lt;K in keyof A&gt;(**scope**: [Scope](https://frontside.com/effection/api/v4-next/Scope.md), **key**: K, **args**: A[K] extends (...**args**:  any) => unknown ? Parameters&lt;A[K]&gt; : &lbrack;&rbrack;) => A[K] extends (...**args**:  any) => unknown ? ReturnType&lt;A[K]&gt; : A[K]</dt>
<dd class="flex flex-col [&>pre]:mb-3">
Call an API as it exists on `scope`.
</dd>
</dl>


### See
* createApi

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/types.ts#L428)
