DEV Community

Cover image for Introducing FastSchema: A Powerful, Go-Based Web Framework & Headless CMS
Phuong Nguyen
Phuong Nguyen

Posted on

Introducing FastSchema: A Powerful, Go-Based Web Framework & Headless CMS

Hey dev.to community! 👋 I'm excited to introduce you to FastSchema, a modern, Go-based web framework and headless CMS that combines flexibility, scalability, and ease of use. Whether you're building a simple website or managing dynamic content at scale, FastSchema has the tools to streamline your workflow.

Check out this quick video overview of FastSchema Headless CMS:

What is FastSchema?

FastSchema is a platform designed for developers and content managers alike. Built with Go for performance, it allows developers to extend functionality with Go code or JavaScript plugins, while offering non-developers a simple, no-code admin interface for managing content.

Here are some of the core features that make FastSchema stand out:

  1. Dynamic Content Management: Manage content models and update your structure on the fly through the admin dashboard - no coding required.

  2. Real-Time Updates: Any changes made to content are instantly propagated to all subscribed clients, ensuring real-time content delivery.

  3. Flexible Plugin System: Developers can extend FastSchema's functionality using JavaScript plugins, allowing full customization.

  4. Built-in File Management & OAuth2: Easily handle file uploads, storage, and serve files through the CMS, with OAuth2 support for authentication.

  5. OpenAPI Support: Automatically generate OpenAPI documentation for your API endpoints, making it easier for your team to collaborate and integrate.

  6. RBAC (Role-Based Access Control): Manage user permissions effectively with a flexible RBAC system that ensures the right users have the correct access levels.

Why Choose FastSchema?

FastSchema isn’t just another CMS. It’s built to be scalable, developer-friendly, and perfect for a wide range of projects. Here’s why you should consider it:

  • Performance: Powered by Go, FastSchema is built to handle heavy traffic with speed and efficiency.

  • Scalability: Whether you're working on a small site or scaling up for enterprise-level traffic, FastSchema adapts easily to your needs.

  • Portability: FastSchema runs smoothly in any environment, from on-premises setups to cloud or containerized infrastructures like Docker.

  • Developer-Friendly: Extend FastSchema with Go or JavaScript plugins without modifying the core codebase, letting you focus on building features.

  • Non-Developer Friendly: The clean, intuitive admin panel allows non-technical users to manage content, making it easy to collaborate with the whole team.

Getting Started with FastSchema

Here’s how you can install and start using FastSchema. Choose the method that works best for you:

Method 1: Using Docker

The easiest way to get started is via Docker. FastSchema provides a pre-built Docker image, so dependencies are handled for you.

  • Step 1: Pull the Docker image...
  docker pull ghcr.io/fastschema/fastschema:latest
Enter fullscreen mode Exit fullscreen mode
  • Step 2: Run the container...
  mkdir data
  docker run \
    -u "$UID" \
    -p 8000:8000 \
    -v ./data:/fastschema/data \
    ghcr.io/fastschema/fastschema:latest
Enter fullscreen mode Exit fullscreen mode

You can now process the setting up by visiting http://localhost:8000?token={token}.

The setup token is displayed in the terminal.

Method 2: Download the Binary from GitHub Releases

If you prefer not to use Docker, you can download the pre-built binary from the FastSchema GitHub Releases page.

  1. Download the Binary:
    • Navigate to the FastSchema GitHub Releases page.
    • Select the latest release.
    • Download the appropriate binary for your operating system (e.g., Linux, macOS, Windows). For example: fastschema_0.5.0_linux_amd64.zip.
  2. Extract the Binary:
    • unzip fastschema_0.5.0_linux_amd64.zip
  3. Run the Binary:
    • Open a terminal or command prompt.
    • Navigate to the directory containing the downloaded binary.
    • Run the following command: ./fastschema start

Method 3: Build from Source

For developers who want to customize FastSchema, building from source is a great option:

  1. Clone the Repository:

    git clone https://github.com/fastschema/fastschema.git
    cd fastschema
    git submodule update --init --recursive
    
  2. Build the Dashboard: (Optional)

    cd pkg/dash
    yarn install && yarn build
    cd ../../ && mkdir -p private/tmp
    
  3. Build and run the Binary:

    go build -o fastschema cmd/main.go
    ./fastschema start
    

    or run the development server:

    make dev
    

Once installed, you can create a new content model directly from the admin dashboard. Simply define your content structure, save, and start managing data instantly!

Use FastSchema as a Web Framework

FastSchema is also a robust Go web framework, providing developers the tools to build dynamic applications. Here’s a simple example of how you can create a web app with FastSchema:

Installation

go get github.com/fastschema/fastschema
Enter fullscreen mode Exit fullscreen mode

This is a basic example of how to use FastSchema to create a simple web application:

package main

import (
  "github.com/fastschema/fastschema/fs"
  "github.com/fastschema/fastschema"
)

func main() {
  app, _ := fastschema.New(&fs.Config{
    Port: "8000",
  })

  app.AddResource(fs.Get("/", func(c fs.Context, _ any) (string, error) {
    _, err := db.Query[*schema.Entity](
      ctx, app.DB(),
      "SELECT * FROM users WHERE id = ?", 1,
    )

    return "Hello World", err
  }))

  app.Start()
}
Enter fullscreen mode Exit fullscreen mode

Plugin system

FastSchema Plugin system that allows you to extend its core functionality with custom features and integrations.

Plugins are written in JavaScript and can be used to add new endpoints, hook into application events, query data, or perform any other custom logic.

Here’s an example of a simple plugin that adds a new endpoint and system schema:

const product = require('./schemas/product.json');
const { getRandomName, ping } = require('./utils');

const Config = config => {
  // Add product schema
  config.AddSchemas(product);

  // Change the fastschema port to 9000
  config.port = '9000';
}

const Init = plugin => {
  // Create a group named 'hello' with two public resources (routes):
  // - hello/ping
  // - hello/world
  plugin.resources
    .Group('hello')
    .Add(ping, { public: true })
    .Add(world, { public: true });
}

const world = async ctx => {
  const name = await getRandomName();
  return `Hello, ${name}!`;
}
Enter fullscreen mode Exit fullscreen mode

JavaScript SDK

FastSchema Javascript SDK (NPM) is a powerful tool that allows you to interact with the FastSchema API programmatically. It works in both Node.js and browser environments, making it easy to integrate FastSchema with your front-end applications.

Here’s a simple example of how you can use the SDK to fetch data from a FastSchema instance:

import { FastSchema } from "fastschema";

// Create a new instance of FastSchema
const fs = new FastSchema("https://localhost:8000");

// Login
await fs.auth().login({
  login: "admin",
  password: "123",
});

// Initialize: This must be called before any other operation
await fs.init();

// Create schema
await fs.schemas().create({
  // ... schema definition
});

// Get content
fs.schema("tag").get<Tag>(params);

// Create content
const createdTag = await fs.schema("tag").create<Tag>({
  name: "Tag 01",
  description: "A description",
});

// and many more operations...
Enter fullscreen mode Exit fullscreen mode

Adding Real-Time Updates

FastSchema allows you to subscribe to content changes in real time. Whether you’re running a news site, a real-time dashboard, or any other dynamic application, you can subscribe to updates as they happen.

The real-time updates api can be subscribed to using websockets or the JavaScript SDK.

Here’s a code example to illustrate how easy it is to subscribe to changes using the SDK:

const schemaTag = fs.schema("tag");

const cb1 = (data: T, event: EventType, error: Error) => {
  console.log("Event:", event, "Data:", data, "Error:", error);
};

const cb2 = (data: T[], event: EventType, error: Error) => {
  console.log("Event:", event, "Data:", data, "Error:", error);
};

const cb3 = (data: T | T[], event: EventType, error: Error) => {
  console.log("Event:", event, "Data:", data, "Error:", error);
};

schemaTag.on("create", cb1);
schemaTag.on("update", cb2);
schemaTag.on("delete", cb2);
schemaTag.on("*", cb3);
Enter fullscreen mode Exit fullscreen mode

And even more...

What’s Next?

FastSchema is still evolving, and we’re super excited to see how developers like you will use it to build powerful web apps and headless CMS solutions. Whether you’re working on a small project or a large-scale application, FastSchema has the tools to help you succeed.

Ready to Build?
🚀 Check out the official FastSchema website: fastschema.com
💻 Explore the source code and contribute: GitHub Repository
💬 Join the community and ask questions: Join FastSchema on Discord

We can’t wait to see what you create with FastSchema! Let’s build something amazing together! 🎉

Top comments (0)