Skip to content

RokkitLabs/ExpressSharp

Repository files navigation

🌐 ExpressSharp

Codacy Badge BCH compliance GitHub Workflow Status

👷 Installation

Get it from Nuget

Latest

Download from releases

Latest

🕴️ Usage

GET

The code below shows how to initialise an Express server, how to set up a callback to a path and how to send data back to the user.

using ExpressSharp;
...
Express server = new Express();

server.GET("/helloworld", (req, res) =>
{
  res.Send("Hello, world!");
});

server.Listen(80);

If you visit your browser at http://localhost/helloworld it should display "Hello, world!", this means that it is working successfully.

POST

TODO

Middleware

Middleware is code that is executed before your callback is executed, This example will have a middleware which will just write "Im middleware" to the console when the user accesses a page, however, this can be used for other things such as authentication headers, to avoid repeating code within each callback.

using ExpressSharp;
...
Express server = new Express();

server.Use((req, res, next) =>
{
  Console.WriteLine("Im middleware");
  next();
});

server.GET("/helloworld", (req, res) =>
{
  res.Send("Hello, world!");
});

server.Listen(80);

In this example you may notice the usage of next(), calling this function calls either the next middleware or the callback depending on whether it is the last middleware to be called, middleware is only called if the path exists as a binding.

✨ Contributors


TatoExp

💻

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages