6. 다음은 필자가 개발한 간단한 REST API TEST 도구의 HTML 소스입니다. 여러분도 다음 HTML 소스를 이용해 REST API를 테스트해 보세요.
<html> <head> <meta charset="UTF-8"> <title>REST API TEST</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/ bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHA HRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/ bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0J utlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min. js"></script> <script> function goRestTest() { var apiName = document.getElementById("apiName").value var apiUrl = document.getElementById("apiUrl").value var apiMethod = document.getElementById("apiMethod").value var parameter = document.getElementById("apiParameter").value $.ajax({ type:apiMethod, url:apiUrl, contentType: "application/json", data:parameter, success: function(result) { document.getElementById("response").value = JSON.stringify(result); }, error: function(request,status,error) { document.getElementById("response").value = "code:"+request.status+"\n"+"message:"+ request.responseText+"\n"+"error:"+error; } }); } </script> </head> <body> <div> <div style="margin:10;width:800px"> <h1>Rest API Test</h1> <form name="form1"> <table> <tr> <td width="400"> <div class="form-group"> <label class="control-label">API Name</label> <input type="text" class="form-control" id="apiName" placeholder="API Name"> </div> <div class="form-group"> <label class="control-label">API URL</label> <input type="text" class="form-control" id="apiUrl" placeholder="API URL"> </div> <div class="form-group"> <label class="control-label">API Method</label> <select class="form-control" id="apiMethod"> <option value="POST">POST</option> <option value="GET">GET</option> </select> </div> <div class="form-group"> <label class="control-label">Parameters</label> <textarea class="form-control" id="apiParameter" rows="6"></textarea> </div> <button type="button" class="btn btn-default" onclick="goRestTest()">Submit</button> <button type="cancel" class="btn btn-default">Cancel </button> </td> <td width="390"> <div class="form-group"> <label class="control-label" style="margin:10"> Response</label> <textarea class="form-control" style="margin:10" id="response" rows="16"></textarea> </div> </td> </tr> </table> </form> </div> </div> </body> </html>
이렇게 해서 CORS 설정으로 REST API까지 테스트해 보았습니다. REST API는 다음 오픈스택 공식 사이트에서 좀 더 자세하고 다양한 정보를 확인할 수 있습니다.