Skip to content
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

Adding a factory method to create a request/response (http package) from a request/response (io package) #8

Closed
Pacane opened this issue Apr 11, 2015 · 3 comments

Comments

@Pacane
Copy link

Pacane commented Apr 11, 2015

I think it could be cool to be able to create one of these when I'm using another framework that's using io.HttpResponse, I like the Future api you provide.

ie: using redstone.dart

import 'package:http/http.dart' as http;
import 'dart:io';

// this returns an HttpResponse from dart:io
HttpResponse resp = await app.dispatch(req);
// what I'd like to do then
http.HttpResponse myResponse = new http.HttpResponse.fromIoResponse(resp);
// use it ..
String body = await myResponse.body;
@nex3
Copy link
Member

nex3 commented Apr 13, 2015

Do you mean HttpClientResponse? HttpResponse is a server-side class, and this package is only for client-side HTTP.

Regardless, I don't think this functionality is useful enough to bake in. It's pretty easy to do the wrapping yourself, if you want, but most of the benefit of this API over dart:io is handling the request/response lifecycle, which is already done by the time you have a response in hand.

@nex3 nex3 closed this as completed Apr 13, 2015
@Pacane
Copy link
Author

Pacane commented Apr 13, 2015

What do you mean it's only for client side?

Taken from the README

The easiest way to use this library is via the top-level functions, although they currently only work on platforms where dart:io is available. They allow you to make individual HTTP requests with minimal hassle:

import 'package:http/http.dart' as http;

var url = "http://example.com/whatsit/create";
http.post(url, body: {"name": "doodle", "color": "blue"})
    .then((response) {
  print("Response status: ${response.statusCode}");
  print("Response body: ${response.body}");
});

http.read("http://example.com/foobar.txt").then(print);

and what is the easy way of wrapping you were talking about?

@nex3
Copy link
Member

nex3 commented Apr 13, 2015

That code snippet is a request being made by an HTTP client.

You can wrap by basically doing the same thing IOClient does internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants