1. Yml Settings
  2. πŸ§‘β€πŸ³ api.yml

Yml Settings

πŸ§‘β€πŸ³ api.yml

Introduction

The api.yml file is essential for configuring API adapters, specifically for the Directus SDK API and the Fetch API. You can define multiple adapters within this file to suit your application's needs.

Overview

This section provides a detailed breakdown of the components within the api.yml file, explaining how the internal @tanglemedia packages utilize this configuration.

Here is an example of the api.yml file:

        default: 'directus'

adapters:
  # THIS IS A FETCH ADAPTER, EXAMPLE: FOR YOUR LARAVEL API
  fetch:
    baseUrl: /
    configuration:
      pathPrefix: '/crm/api/v1'
      metaKey:
        - from: 'data.pagination'
          to: 'pagination'

  # THIS IS A DIRECTUS API ADAPTER FOR A CLIENT AUTHENTICATION
  directus-client:
    adapter: 'directus'
    configuration:
      host: $PUBLIC_DIRECTUS_HOST
      protocol: $PUBLIC_DIRECTUS_PROTOCOL
      # includeTotals: true
      auth:
        mode: 'json'
        config:
          storage: 'localStorage'
          autoRefresh: true
          msRefreshBeforeExpires:
          credentials: 'include'

  # THIS IS A DIRECTUS API ADAPTER FOR A STATIC AUTHENTICATION
  directus-static:
    adapter: 'directus'
    configuration:
      host: $PUBLIC_DIRECTUS_HOST
      protocol: $PUBLIC_DIRECTUS_PROTOCOL
      staticToken: $PUBLIC_DIRECTUS_ACCESS_TOKEN

      

Default Adapter

The Default value serves as a fallback for the @tanglemedia/svelte-starter-core package. If you do not specify an API adapter key when resolving the adapter configuration, this default will be used.

Adapters

The Adapters section contains all your API adapter configurations. This allows for multiple adapters, each with different configurations, names, and actions. Currently, two primary types of adapters are supported:

  • Fetch Adapter: For standard REST API calls, typically used with a PHP/Laravel backend.
  • Directus Adapter: Specifically designed for use with Directus SDK.

Fetch Adapters

The Fetch Adapters configuration is intended for standard REST API calls. Here’s what you need to know:

BaseURL

  • Description: [To Be Determined]

Configuration

  • Description: [To Be Determined]

Directus Adapters

The Directus Adapters are tailored for Directus SDK interactions. Below are the key configurations:

Adapter Key

  • Description: This key is generally consistent across all your Directus adapters and often matches your default value.

Configuration Options

  • host: Your Directus backend URL.
  • protocol: The protocol used for your Directus backend (e.g., http or https).
  • auth.mode: The authorization mode (e.g., json or cookie), defaulting to json. This determines how authorization payload information is sent from the server to your application.
  • auth.config.storage: The storage mode for your authentication data (e.g., localStorage, cookie, or sessions), with localStorage as the default.
  • auth.config.autoRefresh: A boolean indicating whether the API should automatically call the refresh endpoint periodically, based on your settings.
  • auth.config.msRefreshBeforeExpires: The interval (in milliseconds) for calling the refresh API, defaulting to 30000.
  • auth.config.credentials: This option specifies whether to include credentials in your API calls, defaulting to include.

Conclusion

By organizing your API adapters within the api.yml file, you can effectively manage interactions with different backend services. Ensure to configure each adapter according to your application's requirements for optimal functionality.