Some API endpoints for articles
#245
rest-api
into master
6 years ago
@ -0,0 +1,15 @@
|
||||
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
|
||||
|
||||
<div id="api"></div>
|
||||
|
||||
<script>
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "/Plume/api.yaml",
|
||||
dom_id: '#api',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIBundle.SwaggerUIStandalonePreset
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
</script>
|
@ -0,0 +1,45 @@
|
||||
openapi: "3.0"
|
||||
Review
is this autogenerated? is this autogenerated?
Review
not yet, but it may be possible thanks to canapi… not yet, but it may be possible thanks to canapi…
|
||||
info:
|
||||
version: "1.0.0"
|
||||
title: "Plume REST API"
|
||||
|
||||
servers:
|
||||
- url: http://localhost:7878/api/v1
|
||||
description: Your local instance
|
||||
- url: https://baptiste.gelez.xyz/api/v1
|
||||
description: Demo instance
|
||||
|
||||
paths:
|
||||
/posts/{id}:
|
||||
get:
|
||||
description:
|
||||
Retrieves a post by its ID.
|
||||
responses:
|
||||
'200':
|
||||
The post was found
|
||||
'403':
|
||||
The post exists, but you don't have the rights to fetch it (it is probably a private draft)
|
||||
'404':
|
||||
The post was not found
|
||||
/posts/:
|
||||
get:
|
||||
description:
|
||||
List posts.
|
||||
|
||||
definitions:
|
||||
Post:
|
||||
type: "object"
|
||||
properties:
|
||||
title:
|
||||
type: "string"
|
||||
example: "Hello, world!"
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
example: 42
|
||||
subtitle:
|
||||
type: "string"
|
||||
example: "My first post."
|
||||
content:
|
||||
type: "string"
|
||||
format: "<p>This is my first post. Thanks for reading.</p>"
|
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "plume-api"
|
||||
version = "0.1.0"
|
||||
authors = ["Bat' <baptiste@gelez.xyz>"]
|
||||
|
||||
[dependencies]
|
||||
canapi = "0.1"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
@ -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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Review
sometimes i dream of lisp indentation style in Javascript. soon, I'll start dreaming of lisp indentation style in rust sometimes i dream of lisp indentation style in Javascript. soon, I'll start dreaming of lisp indentation style in rust
|
||||
|
||||
pub mod posts;
|
@ -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);
|
@ -0,0 +1 @@
|
||||
pub mod posts;
|
@ -0,0 +1,23 @@
|
||||
Review
such as? such as?
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use canapi::Provider;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use diesel::PgConnection;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use rocket::http::uri::Origin;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use rocket_contrib::Json;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use serde_json;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use serde_qs;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use plume_api::posts::PostEndpoint;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use plume_models::db_conn::DbConn;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
use plume_models::posts::Post;
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
#[get("/posts/<id>")]
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
let post = <Post as Provider<PgConnection>>::get(&*conn, id).ok();
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
Json(json!(post))
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
}
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
#[get("/posts")]
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
fn list(conn: DbConn, uri: &Origin) -> Json<serde_json::Value> {
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
let query: PostEndpoint = serde_qs::from_str(uri.query().unwrap_or("")).expect("Invalid query string");
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
let post = <Post as Provider<PgConnection>>::list(&*conn, query);
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
Json(json!(post))
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
||||
}
|
||||
Review
such as? such as?
Review
For instance, if you For instance, if you `GET /api/v1/posts?title=Hello%20world`, only posts with the `Hello world` title should be shown (`title` is not the best example, but `author_id` could be interesting for instance)
trinity-1686a
commented 6 years ago
Review
So is this (at least partially) blocked by #149, or not related? So is this (at least partially) blocked by #149, or not related?
Review
No, actually we just need to get the raw query params, and deserialize them to No, actually we just need to get the raw query params, and deserialize them to `PostEndpoint` with something like `serde_qs`.
|
exciting Version number