Hide
Home
RSS

Web frameworks in Nim10th October 2019

Recently I've been playing around with some web-development things in Nim. This was prompted by having to create some simple servers/websites at work, and using both Nim with Jester + Karax and .NET + Angular I noticed that both had their pros and cons. I also of course maintain this website which uses PHP, and that prompted me to try out an idea I had in my webexperiment repo, which allows you to edit the files that gets served and have the server rebuild them as you visit them. Yesterday I started thinking about another part of server/web API design, namely documentation. Nim has documentation comments as a core part of the language, even being represented in the AST as its own node kind. So I was wondering if you could add these documentation comments to routes in Jester and have it generate some kind of API documentation. But it dawned on me that since Jester allows us to return pretty much anything from a route it would be nigh impossible to output any sort of information about return types (input types would be slightly easier, but still a bit hairy, and close to impossible for POST request bodies). This made me realise that it should be possible to write something in Nim with a DSL close to that of Jester, but without throwing away Nims great type system. Jester is after all based on Sinatra, a Ruby library, so it makes sense that it behaves in this way, but I can't shake the feeling that there is a better way. If the DSL contained input/output types and documentation comments it would be possible to create type-safe, auto-documententing web API in a fairly easy manner. Sprinkle on a bit of logic like with my explanations project and it could even tell you what output you would get for different inputs in the documentation.

Powered by CouchCMS