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
shell := /bin/bash
@ -30,3 +29,9 @@ run:
test:
@ cargo 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`.
* `tests.rs`: this contains tests for the specific module. This can also be a
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;
pub fn routes() -> Vec<rocket::Route> {
routes![
world,
hello,
name_age
]
}
#[get("/world")]
pub fn world() -> &'static str {
fn world() -> &'static str {
"Hello, world!"
}
#[get("/<name>")]
pub fn hello(name: String) -> String {
fn hello(name: String) -> String {
format!("Hello, {}", name)
}
#[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)
}

View File

@ -2,7 +2,7 @@ use rocket::local::Client;
use rocket::http::Status;
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![super::world, super::hello, super::name_age])
rocket::ignite().mount("/", super::routes())
}
#[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;
// use rocket_contrib::json::Json;
// use rocket::Route;
use http::{Request, Response};
mod controller;
use controller as ctrl;
pub fn routes() -> Vec<rocket::Route> {
routes![search_streets]
routes![
search_streets,
]
}
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
#[get("/search?<street>")]
pub fn search_streets(street: String) -> String {
// Build the request
let mut request = Request::get(
"https://www.ivago.be/nl/particulier/autocomplete/garbage/streets")
.body(())
.unwrap();
// // Build the request
// let mut request = Request::get(
// "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets")
// .body(())
// .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;
// Route modules
mod hello;
mod ivago;
fn rocket() -> rocket::Rocket {
rocket::ignite()
.mount(
"/hello",
routes![
hello::world,
hello::hello,
hello::name_age
]
).mount(
"/ivago",
ivago::routes()
)
.mount("/hello", hello::routes())
.mount("/ivago", ivago::routes())
}
fn main() {