You are reading the Orion 1.x documentation.
Version 1.x is no longer maintained. The current version is 2.x.
TypeScript SDK
Configuration
Learn how to set the API URL, configure authentication, and configure the underlying HTTP client.
API URL
Orion.init('https://your-api.test');
API Prefix
By default, the prefix value is set to api, however, in some cases you might want to change that.
Orion.init('https://your-api.test', 'api/v1');
// or
Orion.setPrefix('api/v1');
Auth Driver
import {AuthDriver} from '@tailflow/laravel-orion/lib/drivers/default/enums/authDriver';
Orion.init('https://your-api.test', 'api', AuthDriver.Sanctum);
// or
Orion.setAuthDriver(AuthDriver.Sanctum);
Token
import {AuthDriver} from '@tailflow/laravel-orion/lib/drivers/default/enums/authDriver';
Orion.init('https://your-api.test', 'api', AuthDriver.Sanctum, 'test-access-token');
// or
Orion.setToken('test-access-token');
Integration with Sanctum for SPA
Before you can make requests to the API, CSRF protection needs to be initialized.
import {AuthDriver} from '@tailflow/laravel-orion/lib/drivers/default/enums/authDriver';
Orion.init('https://your-api.test');
Orion.setAuthDriver(AuthDriver.Sanctum);
try {
await Orion.csrf();
// now you can make requests to the API
const posts = await Post.$query().get();
} catch (error) {
console.error('Unable to retrieve CSRF cookie.');
}
Customizing Axios Instance
import axios from 'axios';
Orion.makeHttpClientUsing(() => {
const client = axios.create();
client.interceptors.request.use(...);
return client;
});