Added docs; started README; started ivago

master
Jef Roosens 2021-03-11 20:52:30 +01:00
parent 1ff5682fd9
commit ba5d149a60
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
8 changed files with 44 additions and 27 deletions

View File

@ -1,5 +1,4 @@
IMAGE := rust_api:latest IMAGE := rust_api:latest
shell := /bin/bash shell := /bin/bash
@ -30,3 +29,9 @@ run:
test: test:
@ cargo test @ cargo test
.PHONY: test .PHONY: test
# Documentation
docs:
@ cargo doc --no-deps
.PHONY: docs

View File

@ -17,3 +17,5 @@ Each module contains the following base files:
`controller.rs` becomes its own module folder named `controller`. `controller.rs` becomes its own module folder named `controller`.
* `tests.rs`: this contains tests for the specific module. This can also be a * `tests.rs`: this contains tests for the specific module. This can also be a
module directory if need be. module directory if need be.
Every module has a `routes` function that returns its route macros.

View File

View File

@ -1,16 +1,24 @@
#[cfg(test)] mod tests; #[cfg(test)] mod tests;
pub fn routes() -> Vec<rocket::Route> {
routes![
world,
hello,
name_age
]
}
#[get("/world")] #[get("/world")]
pub fn world() -> &'static str { fn world() -> &'static str {
"Hello, world!" "Hello, world!"
} }
#[get("/<name>")] #[get("/<name>")]
pub fn hello(name: String) -> String { fn hello(name: String) -> String {
format!("Hello, {}", name) format!("Hello, {}", name)
} }
#[get("/world?<name>&<age>")] #[get("/world?<name>&<age>")]
pub fn name_age(name: String, age: u16) -> String { fn name_age(name: String, age: u16) -> String {
format!("Hello, {} who is {} years old!", name, age) format!("Hello, {} who is {} years old!", name, age)
} }

View File

@ -2,7 +2,7 @@ use rocket::local::Client;
use rocket::http::Status; use rocket::http::Status;
fn rocket() -> rocket::Rocket { fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![super::world, super::hello, super::name_age]) rocket::ignite().mount("/", super::routes())
} }
#[test] #[test]

View File

@ -0,0 +1,9 @@
/// Searches the Ivago API for streets in the given city
///
/// # Arguments
///
/// * `street` -name of the street
/// * `city` - city the street is in
pub fn search_streets(street: String, city: String) -> Vec<String> {
Vec::new()
}

View File

@ -1,22 +1,23 @@
#[cfg(test)] mod tests; #[cfg(test)] mod tests;
// use rocket_contrib::json::Json; mod controller;
// use rocket::Route; use controller as ctrl;
use http::{Request, Response};
pub fn routes() -> Vec<rocket::Route> { pub fn routes() -> Vec<rocket::Route> {
routes![search_streets] routes![
search_streets,
]
} }
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange // URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
#[get("/search?<street>")] #[get("/search?<street>")]
pub fn search_streets(street: String) -> String { pub fn search_streets(street: String) -> String {
// Build the request // // Build the request
let mut request = Request::get( // let mut request = Request::get(
"https://www.ivago.be/nl/particulier/autocomplete/garbage/streets") // "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets")
.body(()) // .body(())
.unwrap(); // .unwrap();
let response = send(request.body(()).unwrap()); // let response = send(request.body(()).unwrap());
"".to_string()
} }

View File

@ -2,22 +2,14 @@
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
// Route modules
mod hello; mod hello;
mod ivago; mod ivago;
fn rocket() -> rocket::Rocket { fn rocket() -> rocket::Rocket {
rocket::ignite() rocket::ignite()
.mount( .mount("/hello", hello::routes())
"/hello", .mount("/ivago", ivago::routes())
routes![
hello::world,
hello::hello,
hello::name_age
]
).mount(
"/ivago",
ivago::routes()
)
} }
fn main() { fn main() {