Backend Framework for BunJS

🚀 Getting Started with Oxarion: Practical Usage Guide

Are you looking for a fast, modern, and easy-to-use Bun.js web framework? Oxarion is here to help you build web servers, APIs, and real-time apps with minimal fuss. In this post, I’ll sho…


This content originally appeared on DEV Community and was authored by Destian Noval

🚀 Getting Started with Oxarion: Practical Usage Guide

Are you looking for a fast, modern, and easy-to-use Bun.js web framework? Oxarion is here to help you build web servers, APIs, and real-time apps with minimal fuss. In this post, I’ll show you how to get up and running with Oxarion, with practical code examples you can use right away.

⚠️ Note: Oxarion is built specifically for Bun. You must use Bun.js to run Oxarion projects—Node.js is not supported!

⚡ Installation

First, install Oxarion in your project:

bun add oxarionjs

🏁 Creating Your First Server

Let’s create a simple HTTP server that responds with "Hello, Oxarion!".

// myServer.js

import Oxarion from "oxarionjs";

Oxarion.start({
  port: 3000,
  httpHandler: (router) => {
    router.addHandler("GET", "/", (_, res) => {
      res.send("Welcome to Oxarion");
    });
  },
});

Start your server and visit http://localhost:3000 in your browser!

🧩 Using Middleware

Middleware lets you add custom logic to your request/response pipeline. Here’s how to log every request:

router.middleware("/", (req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

You can add as many middleware functions as you like, for things like authentication, parsing, or error handling.

🛣️ Defining Routes

Oxarion makes it easy to define routes for different HTTP methods and paths:

router.addHandler("GET", "/get-req", (req, res) => {
  res.send("This is GET Request");
});

router.addHandler("POST", "/post-req", (req, res) => {
  res.send("This is POST Request");
});

You can access query parameters, request bodies, and more via the req object.

🌐 Real-Time with WebSockets

Building a chat app or real-time dashboard? Oxarion has built-in WebSocket support:

// myWs.js

import Oxarion from "oxarionjs";

Oxarion.start({
  port: 3000,
  httpHandler: (router) => {
    // Upgrade path to accept WebSocket
    router.switchToWs("/ws");
  },

  wsHandler: (watcher) => {
    // Path watcher to handle incoming data
    watcher.path("/ws", {
      onOpen: (ws) => {
        console.log("Ws Opened");
      },
      onClose: (ws, code, reason) => {
        console.log(`Ws Closed: Code: ${code}, Reason: ${reason} `);
      },
      onDrain: (ws) => {
        console.log("Ws Drained");
      },
      onMessage: (ws, message) => {
        console.log(`Incoming Message: ${message.toString()}`);
      },
    });
  },
});

Connect to ws://localhost:3000/ws with your favorite WebSocket client!

🧪 Try the Examples

Check out the examples/ folder in the repo for more sample code:

  • simple_server.js – Basic HTTP server
  • middleware.js – Using middleware
  • routes_wrapper.js – Advanced routing
  • websocket_server.js – WebSocket server

📝 Wrapping Up

Oxarion is designed to get you building web apps and APIs quickly, with a clean and modern API. Whether you’re prototyping or building production apps, give Oxarion a try!

Questions or feedback? Drop a comment below or open an issue on GitHub!


This content originally appeared on DEV Community and was authored by Destian Noval


Print Share Comment Cite Upload Translate Updates
APA

Destian Noval | Sciencx (2025-07-21T04:22:35+00:00) Backend Framework for BunJS. Retrieved from https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/

MLA
" » Backend Framework for BunJS." Destian Noval | Sciencx - Monday July 21, 2025, https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/
HARVARD
Destian Noval | Sciencx Monday July 21, 2025 » Backend Framework for BunJS., viewed ,<https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/>
VANCOUVER
Destian Noval | Sciencx - » Backend Framework for BunJS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/
CHICAGO
" » Backend Framework for BunJS." Destian Noval | Sciencx - Accessed . https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/
IEEE
" » Backend Framework for BunJS." Destian Noval | Sciencx [Online]. Available: https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/. [Accessed: ]
rf:citation
» Backend Framework for BunJS | Destian Noval | Sciencx | https://www.scien.cx/2025/07/21/backend-framework-for-bunjs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.