diff --git a/json-api/src/http.rs b/json-api/src/http.rs
index 92d7e1f..416b277 100644
--- a/json-api/src/http.rs
+++ b/json-api/src/http.rs
@@ -2,9 +2,7 @@ use serde_json::{self, Value};
use hyper::http::HeaderValue;
use hyper::Response;
use hyper::Body;
-use hyper::body::to_bytes;
-use std::u8;
use std::collections::HashMap;
const APP_JSON_HEADER: &'static str = "application/json";
@@ -18,17 +16,6 @@ pub fn set_json_body(response: &mut Response
, values: Value) {
*response.body_mut() = Body::from(values.to_string());
}
-pub async fn parse_json_params(body_raw: &mut Body) -> Result {
- let bytes: &[u8] = &*to_bytes(body_raw).await.unwrap(); // rarely fails
- let values: Value;
- if bytes.len() == 0 {
- values = serde_json::from_str("{}")?;
- }
- else {
- values = serde_json::from_slice(bytes)?;
- }
- Ok(values)
-}
pub fn parse_query_string<'qs>(string: &'qs str)
-> HashMap<&str, &str> {
@@ -52,12 +39,19 @@ pub fn parse_query_string<'qs>(string: &'qs str)
return map;
}
-#[inline]
-pub fn extract_uid(values: &HashMap<&str, &str>) -> u64 {
- // NOTE: this is only to be used _AFTER_ the auth module passes since it
- // guarantees the id is verified
- let map = *values;
- let val = *map.get("id").unwrap();
- let s: String = String::from(val);
- return s.parse::().unwrap();
+// Pulls out Option from a HashMap<&str, &str>
+#[macro_export]
+macro_rules! qs_param {
+ ($obj:expr, $id:literal, $type:ty) => {
+ match $obj.get($id) {
+ Some(val) => {
+ if let Ok(pval) = val.to_string().parse::<$type>() {
+ Some(pval)
+ } else{
+ None
+ }
+ },
+ None => None
+ }
+ }
}