From 203422b272de09ad9d0705f2d74192b615bb3d3a Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 25 Nov 2019 15:17:26 +0100 Subject: [PATCH] add readme --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df5b8f5..3fc1c07 100644 --- a/README.md +++ b/README.md @@ -1 +1,54 @@ -# flumm-fetch \ No newline at end of file +# flumm-fetch + +## Usage Example +### async / await +```javascript +import fetch from "flumm-fetch"; + +// GET +(async () => { + const query = await fetch("https://example.com/file.json"); + const result = await query.json(); + console.log(result); +})(); + +// POST +(async () => { + const opts = { + method: "POST", + body: { + name: "John Doe", + password: "pwd" + } + }; + const query = await fetch("https://example.com/file.json", opts); + const result = await query.json(); + console.log(result); +})(); +``` +### promises +```javascript +import fetch from "flumm-fetch"; + +// GET +fetch("https://google.de") + .then(res => res.text()) + .then(res => console.log(res)) + .catch(console.error); + +// POST +const opts = { + method: "POST", + body: { + name: "John Doe", + password: "pwd" + } +}; +fetch("https://google.de", opts) + .then(res => res.text()) + .then(res => console.log(res)) + .catch(console.error); +``` + +## License +This project is licensed under the MIT license, see [LICENSE](LICENSE). \ No newline at end of file