2-2 JavaScript API Reference

Calling Web Services

playground.restaurant에서 사용된 REST 기반의 웹서비스를 위한 API호출에 대해 알아보도록 하겠습니다. 설명을 따라가면서 API를 호출하여 data 변수에 값을 저장하는 코드를 채워보세요.

url과 jsonQuery, options 변수에는 필요한 정보들이 저장되어 있습니다. 그 중 jsonQuery 변수는 options에 매칭되어 사용되고 있습니다. 두 가지 변수인 url과 options parameter로 사용하는 getUrl 함수를 호출하여 data 변수에 맛집 정보를 저장해보세요.

지금부터 Developer Center의 예제를 통해서 정답을 찾아보도록 하겠습니다!

REST

REST 기반의 웹서비스를 이용하는 API호출 방법은 다음과 같습니다.

http.getUrl(url, options)
http.postUrl(url, params, options)
http.putUrl(url, params, options)
http.deleteUrl(url, params, options)

여기에서 url은 제공하는 웹 서버에 대한 정보입니다.

options 는 JSON기반의 객체이고 다음과 같은 parameter들을 가지고 있습니다.

  • format: This specifies how the response will be processed. It may be one of 'text', 'json', 'xmljs', or 'csv'.

  • query: An object with attribute/value pairs to pass as arguments to the REST service.

  • basicAuth: HTTP Basic Authentication. The value must be an object with "username" and "password".

  • cacheTime: Cache time in milliseconds. By default, all GET requests are cached in memory. An alternate cache time may be provided.

  • headers: An object with key/value pairs for additional HTTP headers. This may be used for custom Content-Type settings (such as XML).

  • passAsJson (POST call only): If set to true, passes the request parameters in the body in JSON format and sets the content type appropriately.

  • returnHeaders: If set to true, returns HTTP headers and status code. This also suppresses exceptions on HTTP error status codes, leaving this to the developer to handle.

var response = http.getUrl('https://api.example.com', {  
    format: 'json',  
    query: {    
        booleanAttribute: booleanAttribute,    
        name: name,    
        restaurantStyle: restaurantStyle,    
        address: address,    
        menuItem: menuItem  
    }
})
page퀘스트2. Bixby로 주변 맛집 찾기

Last updated