2017-01-28 23:51:47 +00:00
|
|
|
import * as https from 'https'
|
|
|
|
|
|
|
|
import * as plugins from './smartrequest.plugins'
|
|
|
|
import * as interfaces from './smartrequest.interfaces'
|
|
|
|
|
|
|
|
import { request } from './smartrequest.request'
|
|
|
|
|
2017-01-29 00:12:42 +00:00
|
|
|
export { request } from './smartrequest.request'
|
|
|
|
export { ISmartRequestOptions } from './smartrequest.interfaces'
|
2017-01-28 23:51:47 +00:00
|
|
|
|
2017-01-29 00:12:42 +00:00
|
|
|
export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
2017-06-09 19:48:16 +00:00
|
|
|
optionsArg.method = 'GET'
|
|
|
|
let response = await request(domainArg, optionsArg)
|
|
|
|
return response
|
2017-01-28 23:51:47 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:12:42 +00:00
|
|
|
export let post = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
2017-06-09 19:48:16 +00:00
|
|
|
optionsArg.method = 'POST'
|
2017-12-14 21:33:48 +00:00
|
|
|
if (
|
|
|
|
typeof optionsArg.requestBody === 'object'
|
|
|
|
&& (!optionsArg.headers || (!optionsArg.headers['Content-Type']))
|
|
|
|
){
|
|
|
|
// make sure headers exist
|
|
|
|
if(!optionsArg.headers) { optionsArg.headers = {} }
|
|
|
|
|
|
|
|
// assign the right Content-Type, leaving all other headers in place
|
|
|
|
Object.assign(optionsArg.headers, {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
}
|
2017-06-09 19:48:16 +00:00
|
|
|
let response = await request(domainArg, optionsArg)
|
|
|
|
return response
|
2017-01-28 23:51:47 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:12:42 +00:00
|
|
|
export let put = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
2017-06-09 19:48:16 +00:00
|
|
|
optionsArg.method = 'PUT'
|
|
|
|
let response = await request(domainArg, optionsArg)
|
|
|
|
return response
|
2017-01-28 23:51:47 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:12:42 +00:00
|
|
|
export let del = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
2017-06-09 19:48:16 +00:00
|
|
|
optionsArg.method = 'DELETE'
|
|
|
|
let response = await request(domainArg, optionsArg)
|
|
|
|
return response
|
2017-01-28 23:51:47 +00:00
|
|
|
}
|