🚀 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!
Top comments (0)