Giter Site home page Giter Site logo

swiftserve's Introduction

SwiftServe - Express-Like Web Server built on top of the Bun

This is a simple Express-like application built using Bun.js, a lightweight web framework. It provides a basic example of creating routes and serving responses. You can use this as a starting point for building more complex applications.

Installation

bun add swiftserve

Getting Started

import swiftserve from "swiftserve";

const app = swiftserve(/* options can be here. Practically same options with Bun.serve */);

// Define a middleware function that logs the request method and URL
app.use((req, res) => {
   console.log(`Received ${req.method} request for ${req.url}`);
});

// Define a route for the "/hello-world" endpoint that returns "Hello World"
app.get('/hello-world', async (req, res) => {
  return res.text('Hello World');
});

// Define a catch-all route that returns a JSON response with a message
app.all('*', async (req, res) => {
  return res.json({ message: 'Hello World' });
});

// Use cors if needed
app.use(swiftserve.cors());

// use static files if needed
app.use(swiftserve.static('/path/to/static/files'));

// Start the server
app.serve();
console.log("Http server run on http://localhost:3000");

// Close the server when it becomes necessary
app.close();

Running the Application

bun run <file>

This will start the server, and you can access it by opening a web browser and navigating to http://localhost:3000/hello-world or any other URL.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! If you have any improvements or suggestions, feel free to open an issue or create a pull request.

Happy coding! ๐Ÿ˜Š

swiftserve's People

Contributors

mdreal32 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.