Introduction
Stric is a powerful, Bun-first framework tailored for crafting high-performance web applications effortlessly. Its core philosophy revolves around speed, scalability, and providing a developer-friendly experience with straightforward, intuitive APIs.
Below is a concise guide to get you started with Stric. The guide covers the initial setup, creating a basic application, defining routes, and launching the server.
Getting Started with Stric
Setting Up Your Project
Begin by setting up a new Bun project and installing the necessary Stric dependencies.
# Initialize a new Bun project
bun init
# Install Stric core and utility packages
bun i @stricjs/app @stricjs/utils
# Initialize a new Bun project
bun init
# Install Stric core and utility packages
bun i @stricjs/app @stricjs/utils
Configuring Your Application
Once the setup is complete, configure the entry point of your application.
Modify the Entry Point File (
index.ts
): Update the content ofindex.ts
to initiate your Stric application.tsimport { init } from '@stricjs/app'; // Initialize and serve the application with a concise syntax init({ routes: ['./src'] });
import { init } from '@stricjs/app'; // Initialize and serve the application with a concise syntax init({ routes: ['./src'] });
Create Route Definitions: In the
src
directory, create a new file for your routes (e.g.,main.routes.ts
).tsimport { routes } from '@stricjs/app'; import { text, json } from '@stricjs/app/send'; // Define and export your routes export default routes() .get('/', () => text('Welcome to Stric!')) .post('/json', ctx => ctx.json().then(json));
import { routes } from '@stricjs/app'; import { text, json } from '@stricjs/app/send'; // Define and export your routes export default routes() .get('/', () => text('Welcome to Stric!')) .post('/json', ctx => ctx.json().then(json));
These route handlers will be automatically recognized and registered by Stric at runtime.
Running Your Application
To launch your application, execute the following command:
# Start the server using the entry point file
bun run index.ts
# Alternatively, you can use the shorthand command
bun .
# Start the server using the entry point file
bun run index.ts
# Alternatively, you can use the shorthand command
bun .
By default, the application will be accessible at localhost:3000.
Customizing the Server Port
You can modify the server port in two ways:
Environment Variable: Set the
PORT
environment variable to your preferred port number.Serve Options: Directly specify the port in the
init
configuration within your entry point file.tsimport { init } from '@stricjs/app'; init({ routes: ['./src'], // Configuration for Bun.serve serve: { port: 8080 } });
import { init } from '@stricjs/app'; init({ routes: ['./src'], // Configuration for Bun.serve serve: { port: 8080 } });
With the configuration above, your server will now listen at localhost:8080.
Next Steps
You have successfully created a basic Stric application! As you continue, the documentation will introduce more advanced concepts and capabilities of the Stric framework.