@randajan/api-kit
v1.2.0
Published
A lightweight wrapper around fetch that always returns a structured JSON response, handling errors and network issues gracefully
Maintainers
Readme
@randajan/api-kit
JavaScript library for rendering structured data in HTML format. It supports automatic detection of tabular structures and visualization of deeply nested objects. It is ideal for debugging, admin interfaces, or displaying API responses.
Installation
Usage
Server
You can use the library as an ES module:
import createApi from "@randajan/api-kit/server";
const apiReponder = ({
code:0,
isAsync:false,
timestamp:false,
trait:(opt)=>opt,
onOk:(resp, opt)=>{},
onError:(resp, opt)=>{ },
throwError:false
});
Client
You can use the library as an ES module:
import createFetch from "@randajan/api-kit/client";
const apiFetch = createFetch({
code:0,
url:"",
fetch:globalThis.fetch,
query:{},
parseHeaders:false, //if true it will parse response headers
resultOnly:false, //if true it will return only result
timestamp:false, //if true it will calculate timestamps
parseBody:(body)=>body, //custom parser for non api-kit server fetches only
trait:(opt)=>opt,
onOk:(resp, opt)=>{},
onError:(resp, opt)=>{ },
requestType:"json", // json or form, the 'type' property is fallback
responseType:"json", // json or form, the 'type' property is fallback
throwError:false
});
Support
If you have any questions or suggestions for improvements, feel free to open an issue in the repository.
License
MIT © randajan
