Api

Coolify

Learn how to use the Coolify API utilities in your Nuxt application.

Leverage the Coolify API to create, control, and manage all your Coolify products through a simple API interface.

Authentication

Before using the API, you'll need to generate an API token from your Coolify dashboard. Visit the Coolify API Authorization docs for detailed instructions.

Server Utilities

The module provides built-in server utilities to interact with Coolify's API endpoints. Here's how to use them:

List All Instances

Create an API endpoint at server/api/v1/coolify/instances/index.get.ts:

export default defineEventHandler(async (event) => {
  // Add your authentication check here
  return useCoolify().instances()
})

Get Specific Instance

Create an API endpoint at server/api/v1/coolify/instances/[name]/index.get.ts:

import type { Instance } from 'nuxt-coolify'

export default defineEventHandler(async (event) => {
  const name = getRouterParam(event, 'name')
  const { instances } = useRuntimeConfig().coolify

  // Validate your query data
  if (name && !Object.prototype.hasOwnProperty.call(instances, name)) {
    throw createError({
      statusCode: 404,
      message: 'Instance not found or not configured.',
    })
  }

  // Add your authentication check here
  return useCoolify().instances(name as Instance)
})

Client Usage

You can easily consume these API endpoints in your Nuxt components using the useFetch composable:

<script setup lang="ts">
const { 
  data: instances, 
  pending, 
  error, 
  refresh 
} = useFetch('/api/v1/coolify/instances')

// Inside functions like `submit handlers` you need to use `$fetch` instead of `useFetch()`, as useFetch is meant to be used at root level of <script setup>.
const submitHandler = async () => {
  const instances = await $fetch('/api/v1/coolify/instances')
}
</script>

<template>
  <div>
    <h2>Coolify Instances</h2>
    <div v-if="pending">Loading...</div>
    <div v-else-if="error">{{ error.message }}</div>
    <div v-else>
      <pre>{{ instances }}</pre>
      <button @click="refresh">
        Refresh Instances
      </button>
    </div>
  </div>
</template>

Available Utilities

The module provides several utility functions through the useCoolify() composable:

  • instances() - Get all instances or a specific instance
  • healthcheck() - Check the health of your Coolify server
  • More utilities coming soon!

Check the Coolify API Reference for a complete list of available endpoints and their usage.