File size: 804 Bytes
63858e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
 * Convert a JS object into GET URL parameters
 * 
 * @param base Base URL atop which to add GET parameters
 * @param params Object to insert into a URL string
 */
export function makeUrl(base: string, params?: object):string {
    if (params){
        let out: string = base + "?";

        Object.keys(params).forEach( k => {
            out += k;
            out += '=';
            out += params[k];
            out += "&";
        })
        return out.replace(/&$/g, "");
    }
    else {
        return base;
    }
};

/**
 * Convert information in GET request into the message for a POST request    
 */
export const toPayload = (toSend) => {return {
    method:"POST",
    body:JSON.stringify(toSend),
    headers: {
            "Content-type": "application/json; charset=UTF-8"
        }
}}