loading words...

Feb 05, 2019 08:22:38

httpie

by @swizecteller | 220 words | 5🔥 | 102💌

Swizec Teller

Current day streak: 5🔥
Total posts: 102💌
Total words: 28628 (114 pages 📄)

Y'know, @lukeed05's httpie is the delightfulest fetch library I have ever used. Just the right level of abstraction, works in node and browser, fits in 634 bytes. 👌

Lemme show you 👇 #200wordsTIL

---

@lukeed05 is going to claim httpie is for #nodejs but last night I successfully used it in the browser. Evidence around 8:34 in this video.

https://youtu.be/FijK8poDCFU?t=515

---

My favorite parts:

- no more futzing around with parsing JSON

- fully Promise and async/await compliant

- all HTTP verbs just work

- 2 arguments for every verb

---

You'd be surprised how rare async/await and promises still are in the #nodejs world. Ecosystem absolutely _littered_ with ancient libraries nobody's touched in 6 years.

---

6 years is ancient in JavaScript 🤔

---

Just look at this delightfulness! 3 lines of code to fetch JSON from a server 👇

try {

const res = await get("https://my.api/get.json");

console.log(res.statusCode)

console.log(res.data)

} catch (err) {

console.error(err)

}

---

Want to post data to your server? Just as easy: Add an object as 2nd argument and httpie takes care of the rest. Serialization, figuring out what the server accepts (right @lukeed05?), returning a parsed response.

try {

const res = await post("https://my.api/get.json", {

body: {

field1: "Data 1",

field2: "Data 2"

}

});

console.log(res.statusCode)

console.log(res.data)

} catch (err) {

console.error(err)

}

---

httpie is delightful. Give it a shot next time you're talking to a server

https://github.com/lukeed/httpie



Originally published at twitter.com

  • 1

    @swizecteller nice!

    Tim Subiaco avatar Tim Subiaco | Feb 05, 2019 17:53:01
contact: email - twitter / Terms / Privacy