Code Monkey home page Code Monkey logo

ring-clr's Introduction

ring-clr

build

Experimental ClojureCLR port of Ring, built mainly for the purpose of providing an example of what a ClojureCLR project might look like, and — in the spirit of ClojureCLR — to have some fun!

Try it out!

Prerequisites

  • brew install dotnet (or any other way of installing .NET)
  • dotnet tool install --global --version 1.12.0-alpha3 Clojure.Main

Running ring-clr

(ns app
  (:require [ring-clr.adapter.httplistener :as server]))

(defn handler [request]
  {:status 200
   :headers {"content-type" "application/json"}
   :body "{\"hello\":\"world\"}"})

(defn -main []
  (server/run-httplistener handler))

Run the above from a REPL, or run the app.cljr file provided with the repo:

CLOJURE_LOAD_PATH=src:demo Clojure.Main -m app

Differences from Ring

Since Ring is essentially an abstraction on top of the Servlet API, and there is no Servlet API in the CLR, the ClojureCLR adapters wrapping the HTTP server implementation will need to be more comprehensive. Currently only the built-in HttpListener server has been provided an adapter, but adding one for e.g. Kestrel should be doable. Other differences should be minimal:

  • Serving a "resource" (i.e. from classpath / jar) not applicable here
  • Made ring.util.codec included in core, and not in a separate project
  • Nothing marked deprecated in Ring has been included in this port
  • No time or effort spent on non-UTF8 encodings — it's 2023

Except for that, things should work pretty much the same, and much of existing middleware should work as-is.

Documentation

The docs for Ring should be valid for almost everything found here. For the cases where a Java type is expected as input our output, the closest CLR equivalent type is used instead:

  • File => FileInfo or DirectoryInfo
  • Date => DateTime
  • InputStream => Stream
  • ByteArrayOutputStream => MemoryStream

If you find anything not mentioned above, or not easily understood, please open an issue!

Development

Run tests

From the project root directory:

CLOJURE_LOAD_PATH=src:test Clojure.Main -m ring-clr.test

TODO

  • Add implementation for all types of StreamableResponseBody
  • Calculate and set content-length header (no Jetty to do it for us)
  • Most of the stuff around serving static files
  • File upload (multipart params) middleware
  • Cookie session store middleware
  • Datetime parsing of other formats than RFC 1123
  • Provide ClojureCLR specific documentation
  • Use .cljr extension for all files, ensure tooling understands it
  • Publish to Nuget, maybe Clojars

ring-clr's People

Contributors

anderseknert avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ring-clr's Issues

Setup CI build pipeline

Create automated tasks for:

  • Running tests
  • Creating releases
  • Pushing to Nuget (possibly Clojars)

Add Kestrel adapter

While the HTTP Listener seems good enough for most purposes, it's not where the action is in the dotnet world. It would be useful to include an adapter for Kestrel, which is the web server used in the ASP.NET framework.

Add content-length middleware

Contrary to e.g. Jetty, the HTTP listener class included in dotnet does not calculate content-length for us. That seems rather good to have included, and even enabled by default to match the behavior of JVM Ring. The right approach would likely be to create a content-length middleware to add this for the types supported in the body of a response, and apply this middleware in the HTTP listener adapter. If content-length is set by other middleware, we should simply leave it be.

Port multipart-params middleware

Multipart params — i.e. file uploads — should be ported from Ring. This looks a little tricky though, as Ring depends on Apache libraries for this, and we'll need to investigate whether this can be done with standard dotnet classes or whether we'll need external dependencies for this purpose.

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.