diff --git a/README.md b/README.md index 97f44af..6dda811 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ npm install hypf bun install hypf ``` -The idea of this tool is to provide frontend-only lightweight solution for fetching APIs with an easy wrapper: +The idea of this tool is to provide lightweight `fetch` wrapper for Node.js, Bun: ```js import hypf from "hypf"; @@ -36,7 +36,38 @@ if (postErr) { } ``` -or browsers +Cloudflare Workers: + +```ts +export default { + async fetch( + request: Request, + env: Env, + ctx: ExecutionContext + ): Promise { + const hypfInstance = await hypf.createRequest( + "https://jsonplaceholder.typicode.com" + ); + + const [getErr, getData] = await hypfInstance.get< + Array<{ + userId: number; + id: number; + title: string; + body: string; + }> + >("/posts"); + + if (getErr) { + console.error("GET Error:", getErr); + } + + return Response.json(getData); + }, +}; +``` + +and Browsers: ```html diff --git a/package.json b/package.json index b6c481d..98d6ec2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hypf", - "version": "0.0.5", + "version": "0.0.6", "description": "Supertiny and stunning HTTP client for frontend apps. Best frontend wrapper for Fetch API.", "main": "./dist/Hyperfetch.js", "repository": "fzn0x/hypf",