Questions tagged [dart-shelf]

Shelf is a web server middleware for Dart. Shelf makes it easy to create and compose web servers and parts of web servers.

This tag is for questions about shelf and shelf extension packages.

Shelf makes it easy to create and compose web servers and parts of web servers. How?

50 questions
10
votes
3 answers

How to serve both dynamic and static pages with Dart and shelf?

Using shelf_static to serve static web pages through Dart is no problem: var staticHandler = createStaticHandler(staticPath, defaultDocument:'home.html'); io.serve(staticHandler, 'localhost', port).then((server) { print('Serving at…
th65
  • 188
  • 2
  • 11
6
votes
1 answer

Setting multiple set-cookie headers in Dart with Shelf

I need to set multiple 'set-cookie' headers in Shelf, but since headers is a Map, setting the second one replaces the first and so on because keys are unique. How can I solve this in Dart?
Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75
6
votes
1 answer

How to create/add middleware that adds default headers to each request

How can I add middleware to the shelf pipeline that adds default HTTP headers to each request?
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
5
votes
2 answers

How to properly create a secure web server with Dart?

This a typical code provided by Dart for a server using Shelf package : import 'dart:io'; import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart'; import 'package:shelf_router/shelf_router.dart'; // Configure routes. final _router…
5
votes
2 answers

Using dart RPC and shelf_auth for some procedures

I'm using dart-lang/rpc with the shelf_rpc package. Some of my Resources require authentication. I decided to go with JWT and want to use the JwtSessionHandler from shelf_auth. My simplified setup looks like this: final ApiServer _apiServer = new…
enyo
  • 16,269
  • 9
  • 56
  • 73
5
votes
1 answer

How can I use shelf_web_socket to listen for http and ws requests on the same port

https://pub.dartlang.org/packages/shelf_web_socket shows this example import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_web_socket/shelf_web_socket.dart'; void main() { var handler = webSocketHandler((webSocket) { …
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
4
votes
1 answer

Dart shelf - Middleware and handler execution order

I'm lost trying to understand how Dart shelf executes the middleware and handlers. From all the documentation I have read (and briefing it up) if you write a Middleware that returns null, then the execution goes down the pipeline. Otherwise if the…
0ver0n
  • 134
  • 8
4
votes
1 answer

Dart Server Side: Where are the advantage of using Shelf rather than IO as a Web Server?

I want to use the RPC library to develop Dart server side Restful. In the library repository, it bring two exemples how to use (https://github.com/dart-lang/rpc-examples/tree/master/bin): Shelf and IO. I would like to understand better the…
Muka
  • 1,190
  • 1
  • 12
  • 27
3
votes
4 answers

How to access Dart shelf post body parameters?

I am using Dart Shelf framework for building an API. Get works fine but I am having issues with post. I couldn't access any of the body parameters of the post request in my server. Here is what I have tried. // shelf-router router.post('/login',…
GunJack
  • 1,928
  • 2
  • 22
  • 35
3
votes
1 answer

Unit testing with dart's shelf_rest

I'm trying to test a Dart REST app run on shelf_rest. Assuming a setup similar to the shelf_rest example, how can one test the configured routes without actually running an HTTP server? import 'package:shelf/shelf.dart'; import…
Todd M
  • 322
  • 2
  • 8
3
votes
1 answer

Streaming text in Dart with Redstone/Shelf

It just occurred to me that it would make sense to stream strings, each representing an element from a database query instead of returning the whole list of them at the end of the process, this might get the first result earlier on the browser. So I…
Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75
2
votes
1 answer

Middleware to change content-type in response header

I am new to server side programming with dart. I made a simple API server with a number routes. I'm using Shelf and ShelfModular packages. I'm trying to use one Middleware to set the content-type of the response. When running, the Middleware runs,…
2
votes
1 answer

Receive files in Dart's Shelf back-end

I'm posting a file from the front-end using this code: final request =MultipartRequest('GET', Uri.parse('http://192.168.0.8:8080/sendfile')); request.files.add(await MultipartFile.fromPath('fromFilePath', 'file.pdf')); StreamedResponse response =…
2
votes
1 answer

How to log the response for a dart shelf request

I'm using the Dart Shelf package and I need to log the response it sends. I've managed to log the request but the response technique is less clear: final handler = const shelf.Pipeline() .addMiddleware(corsHeaders()) …
Brett Sutton
  • 3,900
  • 2
  • 28
  • 53
2
votes
2 answers

How to redirect a request in Dart/shelf?

I'm using shelf in Dart to setup a simple web server. How can I redirect a request from / to /oauth2callback in the example below? I have found this method, but somehow I cannot compile the code even though I import dart:io. import…
abyesilyurt
  • 399
  • 3
  • 13
1
2 3 4