Routing HTTP requests in a Dart server

Suragch
Flutter Community
Published in
9 min readJan 2, 2021

--

Part 2 in a series about Server Side Dart without a framework

original photo source

This article is a continuation in exploring Dart as an HTTP server backend, but without any frameworks or third-party packages. Knowing how to build a Dart server from scratch will not only make you a better developer in general, but will also keep you from being left in the lurch when your favorite framework falls off a cliff.

Go back and read Part 1: Building a Dart server from scratch if you haven’t already. And if you’re following along with the code examples (as you should be), then start with the final project code from that article.

HTTP server requests

Clients can make a variety of different HTTP requests to a server. Here are some examples from jsonplaceholder that I’ve talked about previously in How to make HTTP requests in Flutter:

GET     /posts
GET /posts/1
GET /posts/1/comments
GET /comments?postId=1
GET /posts?userId=1
POST /posts
PUT /posts/1
PATCH /posts/1
DELETE /posts/1

The left-hand side has the HTTP method, or verb as it’s sometimes called. The right-hand side has the path and various query parameters. These methods, paths, and query parameters are all ways of asking the server to do something specific, almost like function calls…

--

--