diff --git a/src/main.rs b/src/main.rs index fb370fe..b549616 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,40 @@ #![feature(proc_macro_hygiene, decl_macro)] +use rocket::response::content::Html; + #[macro_use] extern crate rocket; #[cfg(test)] mod tests; #[get("/")] -fn hello() -> &'static str { - "Hello, world!" +fn home() -> Html { + Html( + format!(" + + Barcode API + + +

Barcode API

+

Use the following URL to get a barcode:

+

https://barcode-api.herokuapp.com/barcode/1234

+ + +")) +} + +#[get("/barcode/")] +fn barcode(barcode: String) -> String { + format!("{{\"barcode\": \"{barcode}\", \ + \"name\": \"Grape Test\", \ + \"fruit\": \"grapes\", \ + \"process\": \"main\", \ + \"standard\": \"premium\", \ + \"market\": \"Woolworths\", \ + \"image\": \"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png\"\ + }}\ +") } fn main() { - rocket::ignite().mount("/", routes![hello]).launch(); + rocket::ignite().mount("/", routes![barcode, home]).launch(); } diff --git a/src/tests.rs b/src/tests.rs index da0b732..075d276 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -2,9 +2,35 @@ use super::rocket; use rocket::local::Client; #[test] -fn hello_world() { - let rocket = rocket::ignite().mount("/", routes![super::hello]); +fn barcode() { + let rocket = rocket::ignite().mount("/", routes![super::barcode]); + let client = Client::new(rocket).unwrap(); + let mut response = client.get("/barcode/1234").dispatch(); + assert_eq!(response.body_string(), Some("{\"barcode\": \"1234\", \ + \"name\": \"Grape Test\", \ + \"fruit\": \"grapes\", \ + \"process\": \"main\", \ + \"standard\": \"premium\", \ + \"market\": \"Woolworths\", \ + \"image\": \"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png\"\ + }\ +".into())); +} + +#[test] +fn home() { + let rocket = rocket::ignite().mount("/", routes![super::home]); let client = Client::new(rocket).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, world!".into())); + assert_eq!(response.body_string(), Some(" + + Barcode API + + +

Barcode API

+

Use the following URL to get a barcode:

+

https://barcode-api.herokuapp.com/barcode/1234

+ + +".into())) }