TypeScript SDK
Configuration
Learn how to set API url, configure authentication, and 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-acess-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;
});