Building a Scalable Web Application with Tigris
What is Tigris?
Tigris is an open-source, modern backend for developing real-time websites and applications. It offers a zero-ops approach, freeing developers to concentrate on their applications without worrying about tedious infrastructure management. With Tigris, developers can build real-time applications without getting bogged down by data infrastructure.
Why Use Tigris?
So, why should you consider using Tigris for your web applications? For one, it handles all deployment, configuration, security, monitoring, and maintenance tasks, as well as infrastructure components. This means less time spent on setup and more time focused on coding. Additionally, Tigris eliminates data silos and sprawling data infrastructure, maintaining data control while avoiding vendor lock-in.
Getting Started with Tigris
To get started with Tigris, you’ll need Docker and Node.js ≥v14 installed on your machine. Once you’ve met these requirements, you can scaffold a Tigris application using the command line.
tigris new my-app
Creating a RESTful Web App
With your Tigris application set up, you can start building a RESTful web application. In this example, we’ll create a blog website using Express.
First, install Express and create a controllers folder in the src directory.
npm install express
mkdir src/controllers
Defining the Model
Next, define the model for your blog using Tigris’s schema. Create a blog.ts file in the models directory and import the necessary modules.
import { Model, Field } from '@tigris/data';
@Model()
class Blog {
@Field() title: string;
@Field() content: string;
@Field() description: string;
}
Creating the Controllers
With your model defined, create the controllers for your application. Create a controller.ts file and define an interface for setting up routes.
interface Controller {
setupRoutes(app: Express.Application): void;
}
class BlogController implements Controller {
private app: Express.Application;
constructor(app: Express.Application) {
this.app = app;
}
setupRoutes() {
// Define routes here
}
}
Configuring the Application
Finally, configure your application by initializing Tigris, creating a database, and setting up routes. Delete the existing code in the app.ts file and replace it with the new configuration.
import express from 'express';
import { Tigris } from '@tigris/core';
import { BlogController } from './controllers/controller';
const app = express();
const tigris = new Tigris('my-database');
tigris.init().then(() => {
const blogController = new BlogController(app);
blogController.setupRoutes();
});
Testing the Application
Once you’ve completed these steps, test your application using cURL. Run the command to create a new blog and verify that it returns a successful response.
curl -X POST \
http://localhost:3000/blogs \
-H 'Content-Type: application/json' \
-d '{"title": "My First Blog", "content": "This is my first blog post", "description": "Welcome to my blog"}'
By following these steps, you’ve successfully built a Jamstack application using Tigris. With its zero-ops approach and real-time capabilities, Tigris is an exciting tool for building scalable web applications.