Skip to content

DSL for building web services

License

Notifications You must be signed in to change notification settings

Vake93/Express.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express.NET

Express.NET is a lightweight, low-ceremony Domain Specific Language (DSL) for building HTTP based services easily. It is based-on .NET / ASP.NET 5. With the use of concise language constructs, this allows you to focus on important bits.. your code and your application! Express.NET handles DELETE, GET, HEAD, POST, PUT and PATCH requests and provides a simple, elegant syntax for returning a response with just a couple of keystrokes.

Hello world

service HelloWorldService;

get Ok ()
{
    return Ok("Hello World from Express.NET!");
}

To get started download the xps binary from the releases section and run

xps new -n HelloWorld
xps run -i .\HelloWorld\

When the web service is started it should display the port the service is running on, this is usually port 5000 for HTTP and port 5001 for HTTPS.

Express.NET Hello World

Swagger at not extra code

Express.NET generates OpenAPI documents and has built-in swagger support. No extra code required!

service PersonService;

csharp
{
    public record Person (string Name, int Age);
    public record Error (string Description);
}

get Ok<Person> | NotFound<Error> (query string name)
{
    if (name == "Vishvaka")
        return Ok(new Person("Vishvaka", 28));
    else
        return NotFound(new Error($"Person with {name} not found."));
}

Express.NET Swagger Support

C# 9 Source File Support

You can have Express.NET DSL and C# source files in the same project! In the weather forecast example, there is a combination of Express.NET DSL and C# source files. Select the language which best suites your need.

Weather Forecast Example Code

Consume NuGet Packages

Bring in your favorite NuGet packgers.

Here is an example using StackExchange.Redis

Project File:

{
  "packageReferences": [
    {
      "name": "StackExchange.Redis",
      "version": "2.2.4"
    }
  ],
  "libraryReferences": [],
  "generateSwaggerDoc": true,
  "addSwaggerUI": true
}

Service File:

using System;
using StackExchange.Redis;

service NuGetDemoService;

csharp
{
    private static ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost:6379");
}

get "ping" Ok<TimeSpan> ()
{
    var db = redis.GetDatabase();
    var pong = await db.PingAsync();
    return Ok(pong);
}

Express.NET NuGet Support

Keep your flow with watch Command

With watch command Express.NET will re-build your project as and when the changers are saved.

Just run your project as

xps watch

Express.NET watch

Examples

More examples can be found here

Things that require imporments

This project is work in progress. Following imporments are still required:

  • Better diagnostic messages.
  • Write documentation on DSL syntax.
  • Hooks into service startup.
  • VS Code Extension.
  • Target .NET 6.

Attributions

About

DSL for building web services

Resources

License

Stars

Watchers

Forks

Packages

No packages published