Code Monkey home page Code Monkey logo

jexpress's Introduction

jexpress

JExpress.java, a light and slow express.js clone written in Java 17 (in one file). It uses virtual threads if run with Java 21 (or Java 19/20 with --enable-preview).

There is also JExpress8.java, a version backward compatible with Java 8.

The full javadoc

Example

public static void main(String[] args) {
  var app = express();
  app.use(staticFiles(Path.of("public")));

  app.get("/hello/:id", (req, res) -> {
    var id = req.param("id");
    record Hello(String id) {}
    res.json(new Hello(id));
  });
  
  app.get("/LICENSE", (req, res) -> {
    res.sendFile(Path.of("LICENSE"));
  });

  app.listen(3000);
}

Run and test

  • Run the application with

    cd src/main/java
    java JExpress.java
    
  • Test the application with Maven

    mvn clean package
    

jexpress's People

Contributors

fenrur avatar forax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fenrur

jexpress's Issues

Demande d'explication sur la gestion des requêtes

Bonjour Monsieur Forax,

Je me vous contacte car je suis très intrigué car votre implémentation express.js en java. Je n'arrive pas à voir dans le code comment sont gérés les appels concurrents. Je vois bien les callbacks mais j'ai l'impression que le serveur ne peut répondre qu'à une requête à la fois.

Pourriez-vous m'éclairer (simplement) ?

Merci beaucoup,
Alexandre

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.