5 ms·
Trivial REST server in various languages to compare
- frizlab 2y agoThe Swift server is implemented using NIO directly, which nobody will do, ever. They probably should’ve used Vapor or Hummingbird…
- phtrivier 2y agoWould have been even more interesting to split the code in different folders (maybe only keeping the global Makefile) as it would have demonstrated the level of boilerplate / config / dependencies needed for what is basically the "hello world" of the web.
- VeejayRampay 2y agothis thread is going to be dozens of replies of people overly defensive of their language producing the whole gamut of "the code in LANGUAGE_X is not optimal, it should use SOME_TECHNOLOGY instead"
- alganet 2y agoWhat is the criteria for chosing a framework vs implementing using language fundamentals? I don't care about one over another, but I would prefer if all examples followed the same approach. It would make the comparison more valuable.
- MortyWaves 2y agoI wondered this too. Personally, as someone that enjoys using C# a lot I was somewhat surprised it's example went with a plain HttpListener like that. But, that seems to be the general theme of all the examples there. Personally I think a more real world method would have been to use the most popular web server framework for the given language. Someone else already commented that the Swift example would never do it this way in a real application.
- cpfohl 2y agoSame thought! Python uses FastAPI. C# with ASP.NET looks similarly terse, and ASP.NET is “built in” (kinda). var app = WebApplication.Create(); app.MapGet("/people", () => new[] { new Person("Ana"), new Person("Filipe"), new Person("Emillia") }); app.Run(); record Person(string Name); The above (struggling to find the backtick on my Mobile keyboard) is straight from the ASP.NET website: https://dotnet.microsoft.com/en-us/apps/aspnet/apis https://dotnet.microsoft.com/en-us/apps/aspnet/apis
- neonsunset 2y agoFor some reason the repo uses outdated Mono (which is limited to ancient .NET Framework APIs and old C# version) which could be the culprit. In any case - https://github.com/begoon/http-server/pull/1 https://github.com/begoon/http-server/pull/1
- brabel 2y agoIt seems that the line is drawn on whether it's possible to do HTTP and JSON using the stdlib without having to write a HTTP message and JSON parser. For the cases where JSON is not in the stdlib, they seem to just use a library. But yeah, that makes the comparison less valuable because ALL languages could have used a library that lets you do the equivalent of the Python version. But it's still valuable to know which languages support this out-of-the-box, perhaps.
- ericcholis 2y agoI was wondering this as well. The Python example almost felt like cheating with FastApi....but I suppose it's also pythonic.
- indulona 2y agoi am surprised at how many languages look more like some kind of yaml configuration file rather than actual program. also of note is to notice how many languages lack good support in standard library and therefore require much more code to be needed.
- mtsr 2y ago> also of note is to notice how many languages lack good support in standard library and therefore require much more code to be needed. That’s fine for web oriented languages. But I sure hope others aren’t including a complete HTTP stack in the standard library.
- brabel 2y agoZig is a system language but it still has HTTP and JSON in the stdlib.
- zihotki 2y agoWhat problem does it address? What is being compared?
- deleted 2y ago[deleted]
- xnx 2y agoNo bash? https://github.com/dzove855/Bash-web-server https://github.com/dzove855/Bash-web-server
- munksbeer 2y agoNo Java, in the top three most widely used languages.
- begoon 2y agoHey, the author here. Agree, I wasn’t consistent with “a framework” vs “just language” approach. Ideally it should be 100% one or another. My idea was to use the standard library as much as possible, but I didn’t eliminate the use of third party libraries entirely if it would allow async/concurrent processing. It all started with Go vs Rust vs Zig as the main point of comparison. Then I added more languages I am familiar with. By far, IMHO, Go is a clear winner in terms of being 100% with the standard library, fully concurrent and quite concise. Sure, JS/TS implementations are also concise but it is different, not natively compiled technology. The language's selection is purely my personal familiarity, so nothing wrong with Java, it’s just not my area.
- dave1999x 2y agoWhy is this REST and not just HTTP?