본문 바로가기

프로그래밍 공부/백엔드

APIs : Endpoint, Paths, Parameters, and Autentication.

728x90

An Application Programming Interface is a set of commands, functions, protocols, and objects that programmers can use to create software or interact with an external system.

 

다른 개발자가 만들어놓은 프로그램을 외부의 다른 개발자가 갖다가 쓰는거. 

데이타 제공자와 개발자간의 계약. 예를 들어, 지역별 범죄율 데이터, 날씨, 공공 데이터, jquery 등등

Your server request-----> API ----->request someone else's
server
<---response <-----response

 

실험

JokeAPI

https://sv443.net/jokeapi/v2/

 

JokeAPI

JokeAPI is a RESTful API that serves jokes from many categories while also offering a lot of filtering methods

v2.jokeapi.dev

1. End points를 찾아라 - An endpoint is an access point to send the HTTP requests to and get your response.
JokeAPI offers these following endpoints:

/카테고리 전까지가 엔드포인트.
프로그래밍과 크리스마스 조크로 카테고리를 고르자, 아래의 url이 생성되었다.

3. Path

엔드포인트 뒷부분, 그러니까 /programming,Christmas 가 Path

개발자가 미리 지정해 놓은 부분, so somewhere on this joke API server, they have to be able to catch when a request is made to this URL/programming path 프로그래밍 조크만 필터해서 보여줄 수있게 미리 만들어짐.

 

미리 생각해둘 수 없는 부분의 필터는 어떻게 할까?  -> a PARAMETERS

4. Parameters

커스텀쿼리 -  URL/ path 다음에 ?contains=debugging 으로 나오는 부분이 PARAMETERS!

contains: key (가변)

=debugging: query (가변)

 

 

 

 

 

 

 

 

 

 

 

The first query follows a "?" and every subsequent query follows an "&amp;"

URL /path ? key=query & key = query

 

5. 결과

위의 url을 주소창에 넣고 엔터

더보기
{
    "error": false,
    "category": "Programming",
    "type": "single",
    "joke": "The six stages of debugging:\n1. That can't happen.\n2. That doesn't happen on my machine.\n3. That shouldn't happen.\n4. Why does that happen?\n5. Oh, I see.\n6. How did that ever work?",
    "flags": {
        "nsfw": false,
        "religious": false,
        "political": false,
        "racist": false,
        "sexist": false,
        "explicit": false
    },
    "id": 123,
    "safe": true,
    "lang": "en"
}

css가 필요하지만 값은 출력됨.