> For the complete documentation index, see [llms.txt](https://docs.mqnicrnd5.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mqnicrnd5.com/guide/rest-api/road-weather-offer.md).

# 도로기상정보 (제공)

## 1. 실시간도로환경 기상정보 조회 (GetRoadWeather)

### 요청 URL

```url
http://service.mqnicrnd5.com/api/v1/rw/offer/grw
```

### 연계 주기

요청 시 (정보 갱신 주기 : 10분)

### 프로토콜

HTTPS

### HTTP 메서드

GET

### 데이터 포맷

{% file src="/files/aqbsmF14tAJvhzx73yaK" %}

### 참고사항

API를 요청할 때 다음 예와 같이 HTTP 요청 헤더에 접근 토큰(Access Token) 을 추가해야 합니다. <mark style="color:purple;">**접근 토큰 앞에 "Bearer " 문자열을 추가해야 한다는 점에 주의하세요.**</mark>

```
> GET /api/v1/rw/offer/grw?locgovId=41590&spatialUnit=mec&reqId=RSU90002,RSU00047,RSU00046
> Host: service.mqnicrnd5.com
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Bearer <접근 토큰>
```

### 요청 예시

```sh
curl --location 'http://service.mqnicrnd5.com/api/v1/rw/offer/grw?locgovId=41590&spatialUnit=mec&reqId=RSU90002,RSU00047,RSU00046' \
--header 'Authorization: Bearer <접근 토큰>'
```

### 응답 예시

```json
[
    {
        "mecId": "RSU00002",
        "linkId": null,
        "dttm": "20240619073552",
        "roadWeather": {
            "weatherData": {
                "ta": -3.1,
                "hm": 17.1,
                "pa": 1025.7,
                "ws": 10.1,
                "wd": 0.1,
                "cpsd": 0.0,
                "rn": 0.1,
                "statCd": "24"
            },
            "visibilityData": {
                "vs": 11,
                "at": -3,
                "statCd": "24"
            },
            "roadSurfaceData": {
                "ts": -3.1,
                "ft": -24.6,
                "wfh": 0.1,
                "ilt": 0.1,
                "sd": 0.3,
                "ip": 17.1,
                "st": 3,
                "f": 0.5,
                "statCd": "24"
            }
        }
    },
    {
        "mecId": "RSU00001",
        "linkId": null,
        "dttm": "20240619073550",
        "roadWeather": {
            "weatherData": {
                "ta": -3.1,
                "hm": 17.1,
                "pa": 1025.7,
                "ws": 10.1,
                "wd": 0.1,
                "cpsd": 0.0,
                "rn": 0.1,
                "statCd": "24"
            },
            "visibilityData": {
                "vs": 11,
                "at": -3,
                "statCd": "24"
            },
            "roadSurfaceData": {
                "ts": -3.1,
                "ft": -24.6,
                "wfh": 0.1,
                "ilt": 0.1,
                "sd": 0.3,
                "ip": 17.1,
                "st": 3,
                "f": 0.5,
                "statCd": "24"
            }
        }
    }
]
```

## 2. 실시간도로환경 기상정보 제공 API 구현 예제

다음은 각 언어별 실시간도로환경 기상정보 제공 API 구현 예제입니다.

{% tabs %}
{% tab title="Java" %}

```java

import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.net.URL;

public class CallAPI {

    public static void main(String[] args) {
        String accessToken = "Bearer " + "<접근 토큰>";
        
        String locgovId = "1111054000";
        String spatialUnit = "MEC"; // or LINK
        String reqId = "0000001,0033";
        String reqDttm = "202304012050";

        String apiURL = "http://service.mqnicrnd5.com/api/v1/rw/offer/grw?"
                + "locgvId=" + locgvId + "&"
                + "spatialUnit=" + spatialUnit + "&"
                + "reqId=" + reqId + "&"
                + "reqDttm=" + reqDttm ;

        Map<String, String> requestHeaders = new HashMap<>();
        requestHeaders.put("Authorization", accessToken);
        String responseBody = get(apiURL,requestHeaders);

        System.out.println(responseBody);
    }


    private static String get(String apiUrl, Map<String, String> requestHeaders) {
        HttpURLConnection con = connect(apiUrl);
        try {
            con.setRequestMethod("GET");
            for (Map.Entry<String, String> header : requestHeaders.entrySet()) {
                con.setRequestProperty(header.getKey(), header.getValue());
            }

            int responseCode = con.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) { // 정상 호출
                return readBody(con.getInputStream());
            } else { // 오류 발생
                return readBody(con.getErrorStream());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            con.disconnect();
        }
    }


    private static HttpURLConnection connect(String apiUrl) {
        try {
            URL url = new URL(apiUrl);
            return (HttpURLConnection) url.openConnection();
        } catch (MalformedURLException e) {
            throw new RuntimeException("API URL이 잘못되었습니다. : " + apiUrl, e);
        } catch (IOException e) {
            throw new RuntimeException("연결이 실패했습니다. : " + apiUrl, e);
        }
    }


    private static String readBody(InputStream body) {
        InputStreamReader streamReader = new InputStreamReader(body);


        try (BufferedReader lineReader = new BufferedReader(streamReader)) {
            StringBuilder responseBody = new StringBuilder();


            String line;
            while ((line = lineReader.readLine()) != null) {
                responseBody.append(line);
            }


            return responseBody.toString();
        } catch (IOException e) {
            throw new RuntimeException("API 응답을 읽는 데 실패했습니다.", e);
        }
    }

}

```

{% endtab %}

{% tab title="Python" %}

```python

import requests
import json

def send_get_request():

    accessToken = "Bearer " + "<접근 토큰>"

    locgovId = "1111054000"
    spatialUnit = "MEC" # or LINK
    reqId = "0000001,0033"
    reqDttm = "202304012050"

    apiURL = "http://service.mqnicrnd5.com/api/v1/am/offer/grw?" \
        + "locgovId=" + str(locgovId) + "&" \
        + "spatialUnit=" + str(spatialUnit) + "&" \
        + "reqId=" + str(reqId) + "&" \
        + "reqDttm=" + str(reqDttm)
   
    # Set headers
    headers = {
        "Authorization": accessToken
    }
    
    # Send GET request
    response = requests.get(apiURL, headers=headers)
    
    # Print response
    print("GET Request:")
    print("Response Code:", response.status_code)
    print("Response:", response.text)

if __name__ == "__main__":
    send_get_request()


```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const axios = require('axios');

async function sendGetRequest() {
    const accessToken = "Bearer <접근 토큰>"; // 실제 토큰으로 교체 필요
    const locgovId = "1111054000";
    const spatialUnit = "MEC"; // or LINK
    const reqId = "0000001,0033";
    const reqDttm = "202304012050";

    const apiURL = `http://service.mqnicrnd5.com/api/v1/am/offer/grw?` +
                   `locgovId=${locgovId}&` +
                   `spatialUnit=${spatialUnit}&` +
                   `reqId=${reqId}&` +
                   `reqDttm=${reqDttm}`;

    // Set headers
    const headers = {
        "Authorization": accessToken
    };

    try {
        // Send GET request
        const response = await axios.get(apiURL, { headers });
        console.log("GET Request:");
        console.log("Response Code:", response.status);
        console.log("Response:", response.data);
    } catch (error) {
        console.error("Error in GET Request:", error);
    }
}

sendGetRequest();

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace GetRequestExample
{
    class Program
    {
        static readonly HttpClient client = new HttpClient();

        static async Task Main(string[] args)
        {
            await SendGetRequest();
        }

        static async Task SendGetRequest()
        {
            string accessToken = "Bearer <접근 토큰>"; // 실제 토큰으로 교체 필요
            string locgovId = "1111054000";
            string spatialUnit = "MEC"; // or LINK
            string reqId = "0000001,0033";
            string reqDttm = "202304012050";

            string apiURL = $"http://service.mqnicrnd5.com/api/v1/am/offer/grw?" +
                            $"locgovId={locgovId}&" +
                            $"spatialUnit={spatialUnit}&" +
                            $"reqId={reqId}&" +
                            $"reqDttm={reqDttm}";

            // Set headers
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", accessToken);

            try
            {
                // Send GET request
                HttpResponseMessage response = await client.GetAsync(apiURL);
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                Console.WriteLine("GET Request:");
                Console.WriteLine("Response Code:", (int)response.StatusCode);
                Console.WriteLine("Response:", responseBody);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"\nException Caught!");
                Console.WriteLine($"Message :{e.Message} ");
            }
        }
    }
}

```

{% endtab %}
{% endtabs %}

## 응답 코드

본 페이지의 제공 API 호출 시 발생할 수 있는 응답 코드입니다. 오류가 발생한 경우 아래와 같은 형식의 오류 메세지가 반환됩니다.

```json
{
    "message": "Invalid Input Value",
    "status": 400,
    "code": "C004"
}
```

<table><thead><tr><th width="110" align="center">HTTP 코드</th><th width="110" align="center">에러 코드</th><th align="center">에러 메세지</th><th align="center">설명</th></tr></thead><tbody><tr><td align="center">200</td><td align="center">-</td><td align="center">-</td><td align="center">성공</td></tr><tr><td align="center">400</td><td align="center">C004</td><td align="center">Invalid Input Value</td><td align="center">요청 파라미터가 누락되었거나 형식·값 검증에 실패한 경우</td></tr><tr><td align="center">400</td><td align="center">C004</td><td align="center">Invalid Type Value</td><td align="center">요청 파라미터의 타입이 올바르지 않은 경우</td></tr><tr><td align="center">401</td><td align="center">C004</td><td align="center">Authentication Failed (인증에 실패하였습니다.)</td><td align="center">접근 토큰이 없거나 유효하지 않은(만료 포함) 경우</td></tr><tr><td align="center">401</td><td align="center">C004</td><td align="center">Access Denied (권한이 존재하지 않습니다.)</td><td align="center">해당 API에 대한 권한이 없는 경우</td></tr><tr><td align="center">404</td><td align="center">C004</td><td align="center">Not Found</td><td align="center">조회 대상 데이터 또는 파일이 존재하지 않는 경우</td></tr><tr><td align="center">404</td><td align="center">C004</td><td align="center">Page Not Found (API가 존재하지 않습니다.)</td><td align="center">요청 URL이 존재하지 않는 경우</td></tr><tr><td align="center">500</td><td align="center">C005</td><td align="center">Server Error</td><td align="center">서버 내부 오류가 발생한 경우</td></tr></tbody></table>

자세한 내용은 [Rest API 공통 가이드](/guide/common/rest-api.md)의 오류 코드 항목을 참고하세요.
