News for hackers. Stuff that matters.
Re:Rust is a hard way to make a web API by smolder on Friday January 15, 2021 @07:20PM (#25798507)
Yeah, unless I am building a very performance sensitive web service, either in terms of memory or CPU efficiency, js/typescript or some other web centric language is a much easier choice, and is less costly to build in.

I'm still choosing to write some web stuff in Rust for the experience, for the fact I can compile parts to .wasm and re-use them in a browser too, I enjoy tuning things for performance, and I am not under time constraints for it.

Re:Rust is a hard way to make a web API by vector_spaces on Friday January 15, 2021 @07:30PM (#25798575)
What frameworks are recommended nowadays for Typescript? Is Express still dominant here or are there TS-first options?
Re:Rust is a hard way to make a web API by Azeralthefallen on Friday January 15, 2021 @07:41PM (#25798660)
nest.js is fantastic. https://nestjs.com/
Re:Rust is a hard way to make a web API by ducharmdev on Friday January 15, 2021 @08:11PM (#25798883)
Agreed - trying out nest.js the first time gave me hope that we'd see something like Django for typescript/javascript. Especially paired with nx workspaces, with shared code between front & backend... so nice.
Re:Rust is a hard way to make a web API by enumjorge on Friday January 15, 2021 @09:10PM (#25799275)
How's their authentication solution? Auth is such a critical component of most web apps, yet something that IMO a lot of web frameworks don't fully flesh out compared to how easy it is with Django.

I took a quick look at their auth docs, and while the docs seem pretty detailed, I noticed it involves multiple packages (@nestjs/passport, passport, passport-local, and their corresponding types) that you then have to glue together into a full solution. The instructions also apparently only show you how to store passwords in plain text, and using something like bcrypt to do it yourself is an exercise left to the reader. Not rocket science, as this [1] (older) article pointed out, it's hard finding quality auth-related tutorials in the Node ecosystem. With Django a lot of this stuff is built-in and solidly implemented. Granted, this was after a quick look at the docs, so my impression might be off.

[0] https://docs.nestjs.com/security/authentication

[1] https://hackernoon.com/your-node-js-authentication-tutorial-...

Re:Rust is a hard way to make a web API by Blahah on Friday January 15, 2021 @09:58PM (#25799587)
Passportjs is the standard across all these frameworks. It's modular by design, so you can easily compose the right auth system for your needs. I've always found it quite intuitive and I've never seen anything even nearly as comprehensive in any language.

http://www.passportjs.org/

Re:Rust is a hard way to make a web API by nicoburns on Friday January 15, 2021 @09:28PM (#25799392)
What do you find you get from auth libraries? I've always found them much more trouble than they're worth. But I feel like I must be missing something.
Re:Rust is a hard way to make a web API by foolofatom on Friday January 15, 2021 @07:58PM (#25798784)
I've been using https://tsed.io/ with great success.
Re:Rust is a hard way to make a web API by zumu on Friday January 15, 2021 @08:34PM (#25799032)
I've been out of the JS/TS world for a couple years. Are decorators everywhere now? I will be very sad if so.
Re:Rust is a hard way to make a web API by pas on Saturday January 16, 2021 @05:51AM (#25801468)
TSed has a great dependency injection system, and uses decorators for a few things, I did not find its use excessive.
Re:Rust is a hard way to make a web API by mssundaram on Friday January 15, 2021 @08:54PM (#25799149)
My experience is only n=3 but I've only rarely seen them where I've worked over the past 5 years. The only sane use case I've seen was for tagging logs and metrics.
Re:Rust is a hard way to make a web API by joshxyz on Saturday January 16, 2021 @12:51AM (#25800397)
My codes are written on JS but the sensitive parts are heavily commented with TS types so my vscode intellisense could assist me with correct types.

/* * @type {Map<String, Number>} */

const map = new Map();

Like that.

Express JS is still shit, koajs and fastify are a little better, I used to use nodejs's internal http and https libraries directly but these days uwebsockets.js is what you'd want since it's mature enough already (used by top crypto exchanges).

https://github.com/uNetworking/uWebSockets.js/

And oh it comes with TS types which are cool.

Re:Rust is a hard way to make a web API by girvo on Friday January 15, 2021 @08:00PM (#25798796)
I second the NestJS recommendation, but I’ve also got quite far using pretty stock standard Express style middleware with Deno. It’s been a fun experience.
Re:Rust is a hard way to make a web API by simplify on Friday January 15, 2021 @10:04PM (#25799620)
Two I've been lightly following are Redwood[0] and Blitz[1]. Still a long ways behind something like Rails, but promising nonetheless.

[0] https://github.com/blitz-js/blitz [1] https://github.com/redwoodjs/redwood

Re:Rust is a hard way to make a web API by runarberg on Friday January 15, 2021 @07:33PM (#25798596)
If you want static types you can still use typescript in JavaScript as doc comments. If you really want the syntax as well you can always compile your code down to javascript before. So express works just as well with typescript as it does with JavaScript
Re:Rust is a hard way to make a web API by krono on Friday January 15, 2021 @07:51PM (#25798742)
Every single typescript oriented library that I've tried has had a pretty atrocious dev experience and no end of compatibility issues.

I love typescript, but the ecosystem is without a doubt one of the biggest detractors.

Re:Rust is a hard way to make a web API by smt88 on Friday January 15, 2021 @08:07PM (#25798845)
I have written at least 10 apps in TS with dozens of libraries, including some server-only stuff.

All the problems I've had were with JS and npm. TS has been amazing and worked flawlessly. I just can't understand your experience at all.

Re:Rust is a hard way to make a web API by krono on Friday January 15, 2021 @08:40PM (#25799068)
That's alright. We're obviously not working on the same projects, and are likely taking different approaches to reach our goals.
Re:Rust is a hard way to make a web API by girvo on Friday January 15, 2021 @08:01PM (#25798805)
NestJS is quite a bit better in that regard, but in general I agree with your overall point. What do you feel most of these frameworks are missing re. dev experience?
Re:Rust is a hard way to make a web API by krono on Friday January 15, 2021 @08:21PM (#25798958)
Mostly use other languages for back-end systems, but I will definitely be checking out NestJS soon.

With regards to TS, generally, it takes a lot of effort to get it to work. More often than not, getting to that point in a way that is actually useful/practical and cost effective, requires yet another library to be installed.

Just look at the TSLint/ESLint migration problems, the popularity of all those TS runners such as ts-node/ts-node-dev/tsx-watch/ts-babel/etc., the complete lack of interoperability between all those separate pieces.

Many issues and even proposed fixes to parts of the TS ecosystem - which is all community ran - are either ignored, left open because no one seems to be able to figure it out, or deemed to be out of scope.

I don't know how to fix this honestly. Some leadership from Microsoft would be a good start.

Re:Rust is a hard way to make a web API by girvo on Friday January 15, 2021 @08:54PM (#25799154)
Yeah that’s fair: I’m a bit of an early adopter of Deno [0] for that reason, it helps standardise quite a bit of that. Promising, anyway, if a bit rough currently.

[0] https://deno.land

Re:Rust is a hard way to make a web API by Kaze404 on Friday January 15, 2021 @09:49PM (#25799533)
You don't need any of those. TSLint was deprecated long ago, and TS runners are only mildly useful in development (to the point where I don't bother and just `tsc && node dist`). Are you sure it's a problem with the ecosystem?
Re:Rust is a hard way to make a web API by rualca on Saturday January 16, 2021 @07:48AM (#25801889)
> Yeah, unless I am building a very performance sensitive web service, either in terms of memory or CPU efficiency, js/typescript or some other web centric language is a much easier choice, and is less costly to build in.

I really do not understand how convoluted javascript frameworks that require a thousand tools and checkers and dependencies just to put up a hello world are sold as "easier choices", specially when there is no mention of SPAs anywhere.

Is it that hard to deliver static or dynamic HTML+CSS?

Re:Rust is a hard way to make a web API by pjmlp on Saturday January 16, 2021 @05:28AM (#25801378)
I can do the same with Java and .NET based languages.
Re:Rust is a hard way to make a web API by smolder on Sunday January 17, 2021 @01:25AM (#25808641)
Which part? Compiling to .wasm? Java to me is "old reliable" but carries a lot of baggage and leaves a bad taste in my mouth to read/write. C#.NET I have less experience with. Neither can quite match Rust for cpu/memory efficiency, but they definitely have their place being capable, accessible, and efficient languages with robust "ecosystems".
Re:Rust is a hard way to make a web API by pjmlp on Sunday January 17, 2021 @02:31AM (#25808945)
All of them, native code, wasm, whatever.

Yes, they might not match Rust down to the microsecond or byte count, it doesn't matter in distributed computing.

There are bigger fishes to fry as distributed computing problems.

And Rust type system for preventing data races among threads doesn't help when what is being used is distributed IPC across a cluster nodes.

Re:Rust is a hard way to make a web API by smolder on Sunday January 17, 2021 @10:53AM (#25811664)
I understand where you're coming from. I hear the "bigger fish to fry" sentiment often. The point about distributed data races is a good one.

At one point I did a comparison between a mono/Nancy web service and the same web service, feature for feature, built in NodeJS, Rust/rocket, and Go. I built a few different endpoints that did different types of work and load tested them, profiled memory usage, etc. I know mono and perhaps Nancy weren't the best point of comparison, and it's been some time since, but Rust/rocket really impressed me then, including on axes like ease of development and code readability. The perf deltas I saw could matter quite a bit at scale, allowing for fewer/cheaper servers.

I've enjoyed using Rust for a few things since, personally, and am so far pretty unbothered by its shortcomings.

Re:Rust is a hard way to make a web API by hda2 on Friday January 15, 2021 @10:54PM (#25799881)
Pardon my ignorance, but how are you using .wasm in the browser? How are getting values out of the web assembly module?
Re:Rust is a hard way to make a web API by smolder on Friday January 15, 2021 @11:31PM (#25800057)
I used wasm bindgen to make rust code callable from js. https://rustwasm.github.io/docs/wasm-bindgen/
Re:Rust is a hard way to make a web API by ctr_ctr on Friday January 15, 2021 @11:29PM (#25800051)
Re:Rust is a hard way to make a web API by jagged-chisel on Friday January 15, 2021 @11:22PM (#25800011)
JavaScript is used to fetch, initialize, and run the wasm module. As long as the module exports functions, they can be called from JS. There are JS libraries that will automatically setup up bindings for you.
Re:Rust is a hard way to make a web API by mleonhard on Friday January 15, 2021 @10:54PM (#25799879)
Is the JS/TS toolchain still a complicated undocumented mess?

The last time I tried to use the JS/TS dev tools, I wasted many hours because the tools did zero validation of config files. All of the tools happily silently ignore misspelled config key names and invalid values. This makes simply debugging the tools a huge time sink.