# API

Application Programming Interface. Started in 2000 with Salesforce. eBay, Amazon followed suit but wasn't very influential. In 2006, Facebook and Twitter introduced their APIs and soon Google map followed. In 2006, Amazon launched S3, providing developers with scalable, reliable data storage infrastructure with API. Six month later, EC2 was launched to provide resizable compute capacity in cloud, all by using RESTful API. ref : History of API (opens new window)

image-20201215161446556

https://blog.postman.com/intro-to-apis-history-of-apis/

https://blog.postman.com/intro-to-apis-what-is-an-api/

https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

image-20201215162845437

# How API looks like

image-20201215164136950

  1. Endpoint : The main url.
  2. Paths: Unique parameters that the provider classified in advance. Identify a specific resource.
  3. Query: Unique attributes. Value can be customizable by users. First query follows ? mark, others begin with & mark. Sort/filter resources.
  4. Authentication

# API data format

# JSON

JavaScript Object Notation

Lightweight and easy to turn into JS object

# XML

Extensive Markup Language

# HTML

# Request Method

# https (Native Node.js module)

const https = require("https");

https.get("API_URL", (res) => {
  console.log("statusCode", res.statusCode);
  console.log("headers:", res.headers);
});
1
2
3
4
5
6
app.get("/weather", function(req, res) {
  const url =
    "http://api.openweathermap.org/data/2.5/weather?q=seoul&appid=4af4d07cb88e48380fc2418e6f5646d7";
  http.get(url, function(response) {
    console.log(response.statusCode);
    response.on("data", function(data) {
      console.log(data);
    });
  });
});

//<Buffer 7b 22 63 6f 6f 72 64 22 3a 7b 22 6c 6f 6e 22 3a 31 32 36 2e 39 38 2c 22 6c 61 74 22 3a 33 37 2e 35 37 7d 2c 22 77 65 61 74 68 65 72 22 3a 5b 7b 22 69 ... 414 more bytes>
1
2
3
4
5
6
7
8
9
10
11
12

image-20201215172556499

Hexadecimals can be converted to text. But this is still not a JS object. In order to change it back to JS object, we must "parse" the data.

# axios

# fetch

# Parsing

const myData = JSON.parse(data);
1

Turn strings into JS object

Stringify turns objects into strings while maintaining the format.

Last Updated: 3/1/2021, 9:19:08 PM