Coder Social home page Coder Social logo

Comments (3)

jonasfj avatar jonasfj commented on August 15, 2024

@kiesman99 can you check if this is a problem with package:shelf_router or package:shelf?

from dart-neats.

jonasfj avatar jonasfj commented on August 15, 2024

Please re-open if this is related to package:shelf_router :D

from dart-neats.

yahu1031 avatar yahu1031 commented on August 15, 2024

@kiesman99 and @jonasfj yes that might be the problem with package:shelf not sure cause the Response.ok() was from that package. So basically the response needs headers. If we haven't defined headers, that will think it was a file and the content of a file cannot be viewed directly in the web so it will download the file. If the response we expected was text, write the extension to the file downloaded and open it. It will show the content. If it is json data append the extension to the file and open it, you will able to see the content/response we need. So that, if we add headers to the response it will preview in that format.

This is your sample code data you expected right @kiesman99 ??

image

So here is another scenario (mine)

import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf_io.dart' as io;

class Data{
  Handler get handler {
    final router = Router();
    router.get('/', (Request req) {
      return Response.ok(
        'Hello there πŸ‘‹πŸ»',
        // Specifying header solved my emoji issues too.
        // Now I can even write up emojis 😎.
        headers: {'Content-Type': 'text/plain'},
      );
    });
    return router;
  }
}

void main() async {
  final service = Data();
    await io.serve(app, 'localhost', 1031).then(
      (value) => print('API running at http://localhost:${value.port} πŸ”₯πŸ”₯πŸ”₯'));
}

My Output

image

Hope this clarified your issue. Please lemme know if not.

from dart-neats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.