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