modied docs for read_response_json

This commit is contained in:
dowwie 2019-04-14 17:33:55 -04:00
parent 5745a7a67a
commit 67e9c72039
1 changed files with 24 additions and 11 deletions

View File

@ -371,17 +371,30 @@ impl TestRequest {
///
/// ```rust
/// use actix_web::{App, test};
///
/// let mut app = test::init_service(App::new());
/// let payload = r#"{"id":"12345","name":"Nikolay Kim"}"#.as_bytes();
///
/// let req = test::TestRequest::post()
/// .uri("/people")
/// .header(header::CONTENT_TYPE, "application/json")
/// .set_payload(payload)
/// .to_request();
///
/// let result = read_response_json<_, _, _, serde_json::Value>(&mut app, req);
/// use serde::{Serialize, Deserialize};
///
/// #[derive(Serialize, Deserialize)]
/// pub struct Person { id: String, name: String }
///
/// #[test]
/// fn test_add_person() {
/// let mut app = test::init_service(App::new().service(
/// web::resource("/people")
/// .route(web::post().to(|person: Json<Person>| {
/// HttpResponse::Ok()
/// .json(person.into_inner())})
/// )));
///
/// let payload = r#"{"id":"12345","name":"Nikolay Kim"}"#.as_bytes();
///
/// let req = test::TestRequest::post()
/// .uri("/people")
/// .header(header::CONTENT_TYPE, "application/json")
/// .set_payload(payload)
/// .to_request();
///
/// let result = read_response_json<_, _, _, Person>(&mut app, req);
/// }
/// ```
pub fn read_response_json<S, R, B, T>(app: &mut S, req: R) -> T
where