-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Spike] Express vs. Koa for HTTP processing #1255
Comments
@hacksparrow , i've moved this task to In Progress, because you're already working on it. |
This is currently blocked. We need |
It's not necessarily true. We can start to answer most of the questions in this story without having a working |
I posted few thoughts and review comments for Raymond's RFC pull request, start reading here: #1082 (review) In the meeting which I watched from the recording, the decision was made to abandon Koa for now and support Express-style middleware only, at least that's my understanding. I think Koa's design is superior to Express and addresses many pain-points we have encountered during our 5 year jurney with Express, and I really wish we could switch to Koa because I consider it as a more modern successor. However, Express has much larger user base and there are significantly more middleware available. Considering our limited team size and how much work we need to do in other areas, I agree we should NOT pursue Koa and stick to Express for the time being. To keep our code base simple, I am proposing to assume that LB4 applications (REST servers) will be always mounted as an Express middleware and use request/response types from Express everywhere. Let's not complicate our code by supporting different request/response flavours, when most (if not all) of our users are going to follow our guidance and use LB4 with Express. The only thing I'd like to keep configurable is the express factory function. I'd like LB4 users to be able to switch from Express to a compatible framework, e.g. https://www.fastify.io or perhaps something based on https://github.com/mafintosh/turbo-http The specific details about the interaction between Express middleware chain and LB4 sequence, for example error handling, can be discussed and worked out during pull request reviews, at least as far as I am concerned. |
Just want to add that, from my understanding, if we want to get LB to work with Koa in the future, it is still possible but it involves huge amount of interface porting. @hacksparrow , please correct me if I'm wrong. On a related note, if someone wants to use Koa instead of Express, can they write an extension to get it to work, or we need to change our own code in order to support both? |
@bajtos I think we are on the same page. Here are a few more further clarifications:
|
@dhmlau the component which interfaces LB4 to a helper HTTP framework is Reliably porting to Koa from Express might be an effort of 2-3 weeks. The size of this effort depends on various factors - time line, team size etc. Right now we don't have the provision to write extensions to switch frameworks. But if we want to support in future, some sort of abstraction layer should be added to |
@raymondfeng your plan sounds good to me! As for plugging alternate express-compatible implementations like fastify, I'd like us to design our REST layer in such way that For example, if I want to use fastify in my application, then I think that means that I was thinking about the following approach where I assumed the http endpoint factory is a regular function (the code is an illustration only, not something to land as-is): // in @loopback/rest or similar
export function createHttpEndpoint(app, expressFactory, options) {
const expressApp = expressFactory();
expressApp.use(createMiddlewareFromApp(app));
// setup http server using options
}
// @loopback/rest-express
import * as express from 'express';
export function createHttpEndpoint(app, options) {
return createHttpEndpoint(app, express, options);
} Usage in an application - providing my own express version: import {RestApplication, createHttpEndpoint} from '@loopback/rest';
import * as express from 'express';
const app = new RestApplication();
// configure controllers, etc. perhaps via boot
const server = await createHttpEndpoint(app, express, {port: 3000}); To make this simpler for the majority of users that don't need to/want to know how the sausage is made: import {RestApplication, createHttpEndpoint} from '@loopback/rest-express';
const app = new RestApplication();
// configure controllers, etc. perhaps via boot
const server = await createHttpEndpoint(app, {port: 3000}); The downside is that The upside is that rest-express will allow us to write tests for the particular combination of these two versions and provide our users a combination that's known to work well. Thoughts? |
Four tasks were identified out of this spike: |
@hacksparrow , since you have the tasks created from the spike. is this ticket good to close? thanks. |
Time boxed to 1 week
Created from the discussion at #1071.
This spike is for doing a practical and deeper comparison between Express and Koa for our underlying HTTP framework.
Acceptance Criteria
Should have answers for the following questions (1 question per line).
The text was updated successfully, but these errors were encountered: