2024-02-26 10:47:35 +00:00
|
|
|
mod error;
|
|
|
|
mod person;
|
2024-02-19 15:11:58 +00:00
|
|
|
|
|
|
|
use axum::{
|
|
|
|
routing::{delete, get, post, put},
|
|
|
|
Router,
|
|
|
|
};
|
|
|
|
use surrealdb::engine::any::Any;
|
|
|
|
use surrealdb::Surreal;
|
|
|
|
|
|
|
|
pub fn create_router(db: Surreal<Any>) -> Router {
|
|
|
|
Router::new()
|
|
|
|
//curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe"}' http://localhost:8080/person/1
|
|
|
|
.route("/person/:id", post(person::create))
|
|
|
|
//curl -X GET http://localhost:8080/person/1
|
|
|
|
.route("/person/:id", get(person::read))
|
|
|
|
//curl -X PUT -H "Content-Type: application/json" -d '{"name":"Jane Doe"}' http://localhost:8080/person/1
|
|
|
|
.route("/person/:id", put(person::update))
|
|
|
|
//curl -X DELETE http://localhost:8080/person/1
|
|
|
|
.route("/person/:id", delete(person::delete))
|
|
|
|
//curl -X GET http://localhost:8080/people
|
|
|
|
.route("/people", get(person::list))
|
|
|
|
.with_state(db)
|
|
|
|
}
|