Added docs; started README; started ivago
parent
1ff5682fd9
commit
ba5d149a60
7
Makefile
7
Makefile
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue