Add canapi and try to use for the API

This commit is contained in:
Bat
2018-09-19 15:49:34 +01:00
parent eb24ba1774
commit 1500267125
16 changed files with 211 additions and 10 deletions
+18
View File
@@ -0,0 +1,18 @@
extern crate canapi;
extern crate serde;
#[macro_use]
extern crate serde_derive;
macro_rules! api {
($url:expr => $ep:ty) => {
impl Endpoint for $ep {
type Id = i32;
fn endpoint() -> &'static str {
$url
}
}
};
}
pub mod posts;
+11
View File
@@ -0,0 +1,11 @@
use canapi::Endpoint;
#[derive(Default, Serialize, Deserialize)]
pub struct PostEndpoint {
pub id: Option<i32>,
pub title: Option<String>,
pub subtitle: Option<String>,
pub content: Option<String>
}
api!("/api/v1/posts" => PostEndpoint);