Skip to main content
You can get the current request’s Context by calling Sonamu.getContext() within API methods.

Basic Usage

Getting Context

Sonamu.getContext() returns the Context of the currently executing API request. It returns the correct Context even during async operations.

When to Use?

1. Check Authenticated User

2. Check Permissions

3. Check Ownership

4. Access Request Info

5. Set Response Headers

Helper Function Patterns

Reusable Auth Check

Ownership Check Helper

Usage in Multiple Locations

In Model Methods

In Frames

In Async Operations

Practical Patterns

Audit Log

Rate Limit Check

Internationalization Support

Cautions

Cautions when using Context: 1. Can only be called within API methods 2. Cannot be called in constructors or class fields 3. Same Context maintained across async boundaries 4. Multiple calls return the same object 5. Recommended to treat Context as read-only

Common Mistakes

Next Steps

SonamuContext

Understanding Context structure

Custom Context

Extending Context

@api Decorator

API basic usage

Error Handling

API error handling