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

rename cx to req #582

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use tide::{Request, StatusCode};

/// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter.
///
async fn retrieve_cookie(cx: Request<()>) -> tide::Result<String> {
Ok(format!("hello cookies: {:?}", cx.cookie("hello").unwrap()))
async fn retrieve_cookie(req: Request<()>) -> tide::Result<String> {
Ok(format!("hello cookies: {:?}", req.cookie("hello").unwrap()))
}

async fn insert_cookie(_req: Request<()>) -> tide::Result {
Expand Down
6 changes: 3 additions & 3 deletions examples/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ fn create_schema() -> Schema {
Schema::new(QueryRoot {}, MutationRoot {})
}

async fn handle_graphql(mut cx: Request<State>) -> tide::Result {
let query: juniper::http::GraphQLRequest = cx
async fn handle_graphql(mut req: Request<State>) -> tide::Result {
let query: juniper::http::GraphQLRequest = req
.body_json()
.await
.expect("be able to deserialize the graphql request");

let schema = create_schema(); // probably worth making the schema a singleton using lazy_static library
let response = query.execute(&schema, cx.state());
let response = query.execute(&schema, req.state());
let status = if response.is_ok() {
StatusCode::Ok
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/cookies/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use std::sync::{Arc, RwLock};
/// # use tide::{Request, Response, StatusCode};
/// # use tide::http::cookies::Cookie;
/// let mut app = tide::Server::new();
/// app.at("/get").get(|cx: Request<()>| async move { Ok(cx.cookie("testCookie").unwrap().value().to_string()) });
/// app.at("/get").get(|req: Request<()>| async move {
/// Ok(req.cookie("testCookie").unwrap().value().to_string())
/// });
/// app.at("/set").get(|_| async {
/// let mut res = Response::new(StatusCode::Ok);
/// res.insert_cookie(Cookie::new("testCookie", "NewCookieValue"));
Expand Down
4 changes: 2 additions & 2 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ impl<State: 'static> Router<State> {
}
}

fn not_found_endpoint<State>(_cx: Request<State>) -> BoxFuture<'static, crate::Result> {
fn not_found_endpoint<State>(_req: Request<State>) -> BoxFuture<'static, crate::Result> {
Box::pin(async move { Ok(Response::new(StatusCode::NotFound)) })
}

fn method_not_allowed<State>(_cx: Request<State>) -> BoxFuture<'static, crate::Result> {
fn method_not_allowed<State>(_req: Request<State>) -> BoxFuture<'static, crate::Result> {
Box::pin(async move { Ok(Response::new(StatusCode::MethodNotAllowed)) })
}
6 changes: 3 additions & 3 deletions tests/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use tide::{Request, Response, Server, StatusCode};

static COOKIE_NAME: &str = "testCookie";

async fn retrieve_cookie(cx: Request<()>) -> tide::Result<String> {
async fn retrieve_cookie(req: Request<()>) -> tide::Result<String> {
Ok(format!(
"{} and also {}",
cx.cookie(COOKIE_NAME).unwrap().value(),
cx.cookie("secondTestCookie").unwrap().value()
req.cookie(COOKIE_NAME).unwrap().value(),
req.cookie("secondTestCookie").unwrap().value()
))
}

Expand Down
18 changes: 9 additions & 9 deletions tests/wildcard.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
use http_types::{Method, StatusCode, Url};
use tide::{http, Request};

async fn add_one(cx: Request<()>) -> Result<String, tide::Error> {
match cx.param::<i64>("num") {
async fn add_one(req: Request<()>) -> Result<String, tide::Error> {
match req.param::<i64>("num") {
Ok(num) => Ok((num + 1).to_string()),
Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)),
}
}

async fn add_two(cx: Request<()>) -> Result<String, tide::Error> {
let one = cx
async fn add_two(req: Request<()>) -> Result<String, tide::Error> {
let one = req
.param::<i64>("one")
.map_err(|err| tide::Error::new(StatusCode::BadRequest, err))?;
let two = cx
let two = req
.param::<i64>("two")
.map_err(|err| tide::Error::new(StatusCode::BadRequest, err))?;
Ok((one + two).to_string())
}

async fn echo_path(cx: Request<()>) -> Result<String, tide::Error> {
match cx.param::<String>("path") {
async fn echo_path(req: Request<()>) -> Result<String, tide::Error> {
match req.param::<String>("path") {
Ok(path) => Ok(path),
Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)),
}
}

async fn echo_empty(cx: Request<()>) -> Result<String, tide::Error> {
match cx.param::<String>("") {
async fn echo_empty(req: Request<()>) -> Result<String, tide::Error> {
match req.param::<String>("") {
Ok(path) => Ok(path),
Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)),
}
Expand Down