nodejs / nodejs/node

Add http.serve() API based on Fetch (Request -> Response)

Đang mở
#63,096 8 bình luận 38 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature request http
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

What is the problem this feature will solve?

Node provides fetch, Request/Response, and Web Streams, but no high level server API using this model.

Other runtimes such as Deno and Bun expose a serve API based on the Fetch contract. In Node, similar patterns are commonly implemented in userland (e.g., frameworks like Hono), which indicates demand for this abstraction.

This was discussed in #42529 and received support, however that issue is focused on request.toWeb(), so opening a separate issue focused on this API.

What is the feature you are proposing to solve the problem?

Add a high-level http.serve(handler) API.

An example shape could be:

http.serve((req) => new Response("ok"))

handler: (Request) => Response | Promise<Response>

This would coexist with the existing http.createServer, and be a high level alternative using WHATWG APIs instead.

What alternatives have you considered?
  • Continue using http.createServer directly.
  • Implement this in userland, or use existing 3rd party solutions.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng việc xem xét API http.createServer hiện có của Node và cuộc thảo luận trong issue #42529. Công việc được đề xuất là định nghĩa và thêm http.serve(handler) sử dụng Request và Response, đồng thời vẫn giữ cho createServer khả dụng. Công việc được xem là hoàn tất khi hình dạng và hành vi của API đã được thống nhất, triển khai và được bao phủ cho các handler đồng bộ và bất đồng bộ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, nodejs
Lĩnh vực
backend-api-design
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.