-
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
Showing
9 changed files
with
745 additions
and
994 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export declare function Get(endpoint: string, header?: object | null, optionalApiAddress?: string | null): Promise<any>; | ||
export declare function Post(endpoint: string, body: object | string | null, header?: object | null, optionalApiAddress?: object | null): Promise<any>; | ||
export declare function Patch(endpoint: string, body: object | string | null, header?: null, optionalApiAddress?: null): Promise<any>; | ||
export declare function Put(endpoint: string, body: object | string | null, header?: null, optionalApiAddress?: null): Promise<any>; | ||
export declare function Delete(endpoint: string, body: object | string | null, header?: null, optionalApiAddress?: null): Promise<any>; | ||
declare function Configurate(api?: string, getAuthorization?: () => string): void; | ||
declare const _default: { | ||
Configurate: typeof Configurate; | ||
}; | ||
export default _default; |
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,59 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Delete = exports.Put = exports.Patch = exports.Post = exports.Get = void 0; | ||
const config = { | ||
api: '', | ||
getAuthorization: () => '', | ||
}; | ||
function HeaderBuilder(header, body = null) { | ||
const headers = { | ||
...header, | ||
...(body ? { 'Content-Type': 'application/json' } : null), | ||
...(config.getAuthorization() ? { authorization: config.getAuthorization() } : null), | ||
}; | ||
return headers; | ||
} | ||
async function Handler(res) { | ||
const json = await res.json(); | ||
if (!res.ok) { | ||
throw json; | ||
} | ||
else { | ||
return json; | ||
} | ||
} | ||
async function Get(endpoint, header = null, optionalApiAddress = null) { | ||
const address = `${optionalApiAddress || config.api}${endpoint}`; | ||
return fetch(address, { method: 'GET', headers: HeaderBuilder(header) }) | ||
.then(Handler); | ||
} | ||
exports.Get = Get; | ||
async function Post(endpoint, body, header = null, optionalApiAddress = null) { | ||
const address = `${optionalApiAddress || config.api}${endpoint}`; | ||
return fetch(address, { method: 'POST', body: JSON.stringify(body), headers: HeaderBuilder(header, body) }) | ||
.then(Handler); | ||
} | ||
exports.Post = Post; | ||
async function Patch(endpoint, body, header = null, optionalApiAddress = null) { | ||
const address = `${optionalApiAddress || config.api}${endpoint}`; | ||
return fetch(address, { method: 'PATCH', body: JSON.stringify(body), headers: HeaderBuilder(header, body) }) | ||
.then(Handler); | ||
} | ||
exports.Patch = Patch; | ||
async function Put(endpoint, body, header = null, optionalApiAddress = null) { | ||
const address = `${optionalApiAddress || config.api}${endpoint}`; | ||
return fetch(address, { method: 'PUT', body: JSON.stringify(body), headers: HeaderBuilder(header, body) }) | ||
.then(Handler); | ||
} | ||
exports.Put = Put; | ||
async function Delete(endpoint, body, header = null, optionalApiAddress = null) { | ||
const address = `${optionalApiAddress || config.api}${endpoint}`; | ||
return fetch(address, { method: 'DELETE', body: JSON.stringify(body), headers: HeaderBuilder(header, body) }) | ||
.then(Handler); | ||
} | ||
exports.Delete = Delete; | ||
function Configurate(api = '', getAuthorization = () => '') { | ||
config.api = api; | ||
config.getAuthorization = getAuthorization; | ||
} | ||
exports.default = { Configurate }; |
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
Oops, something went wrong.