-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b459c5d
commit c464f9d
Showing
6 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod endpoint; | ||
mod error; | ||
|
||
pub use self::error::BodyError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed under the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>. | ||
// This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::borrow::Cow; | ||
|
||
use http::{self, header, Method, Request}; | ||
|
||
use crate::api::BodyError; | ||
|
||
pub trait Endpoint { | ||
/// The HTTP method to use for the endpoint. | ||
fn method(&self) -> Method; | ||
/// The path to the endpoint. | ||
fn endpoint(&self) -> Cow<'static, str>; | ||
|
||
/// The body for the endpoint. | ||
/// | ||
/// Returns the `Content-Encoding` header for the data as well as the data itself. | ||
/// | ||
/// # Errors | ||
/// This method returns an error if the body could not be serialized to JSON. | ||
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> { | ||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed under the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>. | ||
// This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use thiserror::Error; | ||
|
||
/// Errors which may occur when creating form data. | ||
#[derive(Debug, Error)] | ||
#[non_exhaustive] | ||
pub enum BodyError { | ||
/// Body data could not be serialized from form parameters. | ||
#[error("failed to URL encode form parameters: {}", source)] | ||
UrlEncoded { | ||
/// The source of the error. | ||
#[from] | ||
source: serde_urlencoded::ser::Error, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
pub mod api; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} |