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

Remove intermediate Service struct #442

Merged
merged 4 commits into from
Apr 21, 2020
Merged

Remove intermediate Service struct #442

merged 4 commits into from
Apr 21, 2020

Conversation

yoshuawuyts
Copy link
Member

This implements HttpService directly on Server removing the need for the intermediate Service struct. This allows us to remove into_http_service and the server submodule making e.g. nesting apps really easy.

Examples

let mut app = tide::new();
let mut inner_app = tide::new();
inner_app.at("/").get(|_| async { Ok("hello world") });
app.at("/foo").nest(inner_app);
app.listen("localhost:8080").await?;

Future directions

In http-rs/http-types#94 we've introduced the (experimental) Client and Server traits. The hope is that these can replace http-client and http-service including on Tide directly. Because these traits don't carry a connection this would allow us to bypass http_service_mock::make_server and http_mock_service::TestBackend::simulate calls entirely by simply calling app.recv_req instead, making it really easy to test applications:

let mut app = tide::new();
app.at("/").get(|_| async { Ok("hello world") });

let req = Request::new(Method::Get, "http://localhost:8080");
let res = app.recv_req(req).await?;

This removes the need to use the intermediate Service struct making it easier to use Tide's Server.
Now that Service is no longer a thing, we no longer need a submodule to contain it.
Since Server now implement HttpService we no longer need Server::into_http_service
src/server/mod.rs Outdated Show resolved Hide resolved
@yoshuawuyts yoshuawuyts merged commit 1b7fceb into master Apr 21, 2020
@yoshuawuyts yoshuawuyts deleted the self_service branch April 21, 2020 10:38
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

Successfully merging this pull request may close these issues.

None yet

2 participants