DEV Community

Yasser Ameur el idrissi
Yasser Ameur el idrissi

Posted on

I built a Fast and low HTTP router and URL matcher for building Deno servers 🦕.

Xanny finally reached version 1.0 in Dec 2020. According to its official repository, Xanny is a simple, fast and low HTTP router and URL marcher for building Deno servers.
You can assume xanny as a layer built on the top of the Deno that helps manage a server and routes. It provides a robust set of features to develop web and mobile applications.

Let's see some of the core features of Xanny framework:

  • Developer friendly, very expressive and help the developer in their daily use, without sacrificing performance and security.
  • Lightweight and modular design allows for a flexible framework.
  • Focus on high performance.
  • Middleware support, incoming HTTP request can be handled by a chain of middlewares and the final action.
  • Excellent and fluent documentation.

Install Xanny

Assuming you’ve already installed Deno, create a directory and .ts file to hold your code, and make that your working directory.

$ mkdir xanny-app
$ cd xanny-app
$ touch xanny_example.ts
Enter fullscreen mode Exit fullscreen mode

So to use version 1.0.0 of xanny, you would want to import

https://deno.land/x/xanny@v1.0.0/lib/mod.ts
Enter fullscreen mode Exit fullscreen mode

Let's start registering a couple of URL paths and handlers:

import { Application, RequestMethod, HttpRequest, HttpResponse } from "https://deno.land/x/xanny@v1.0.0/lib/mod.ts";

const app = new Application();

const r = app.NewRoute({ maxRoutes:2 });

r.WithMethods(RequestMethod.GET)
    .Path("/")
    .HandleFunc(async function (Request: HttpRequest, ResponseWriter: HttpResponse) {
      ResponseWriter.WithBody("Hello Xanny").Return();
    })
    .Path("/demo")
    .HandleFunc(async function (Request: HttpRequest, ResponseWriter: HttpResponse) {
      ResponseWriter.WithBody("Hello Xanny Demo").Return();
    });

app.ListenAndServe({ port: 8080 });
Enter fullscreen mode Exit fullscreen mode

Here we register two routes mapping URL path to handler. if an incoming request URL matches one of the paths, the corresponding handler is called passingWe believe development must be an enjoyable and creative experience to be truly fulfilling (HttpRequest, HttpResponse) as parameters.

As you can see Xanny provides a very simple and expressive method of defining routes and behavior without complicated routing.

To see the results you need to start a web server on your development machine. You can do this by running the following command in the xanny-app directory:

deno run --allow-net xanny_example.ts
Enter fullscreen mode Exit fullscreen mode

To see your application in action, open a browser window and navigate to http://localhost:8080. You should see the Xanny
Hello Xanny.

We encourage you to contribute to Xanny! Please check out the guidelines about how to proceed.

Whether you’re helping us fix bugs, improve the docs, or spread the word, we’d love to have you as part of the Xanny community! 💪💜 See CONTRIBUTING.md for more information on what we’re looking for and how to get started.
👉 Github Repository

Top comments (0)