페이지

2014년 7월 1일 화요일

REST API

REST
http://en.wikipedia.org/wiki/Representational_state_transfer





REST(Representational State Transfer)
 네트워크 아키텍처 원리의 모음이다. 여기서 네트워크 아키텍처 원리란 리소스를 정의하고 리소스에 대한 주소를 지정하는 방법에 대한 개괄을 말한다. 간단한 의미로는, 도메인 지향 데이터를 HTTP위에서 SOAP이나 쿠키를 통한 세션 트랙킹 같은 부가적인 전송 레이어 없이, 전송하기 위한 아주 간단한 인터페이스를 말한다. 이 두 가지의 의미는 당연히 겹치는 부분과 충돌되는 부분이 있다. 필딩의 REST 아키텍처 형식을 따르면 HTTP 프로토콜을 사용하지 않은 채로 또 월드 와이드 웹에서 전송하지 않고도 아주 커다란 소프트웨어 시스템을 설계하는 것도 가능하다. 또한, 리모트 프로시저 콜을 이용하는 대신에 간단한 XML과 HTTP 인터페이스(REST 원리에 부합하지는 않지만)를 이용해 설계하는 것도 가능하다.
http://ko.wikipedia.org/wiki/REST

8주차 - REST API 설계 및 구현
 REST는 SOAP이 서비스 지향 구조인 것과 달리 자원지향구조(ROA: Resource Oriented Architecture)로 웹 사이트의 컨텐츠(Text, 이미지, 동영상), DB의 내용 등을 전부 하나의 자원으로 파악하여 각 자원의 고유한 URI(Uniform Resource Identifier)를 부여하고, 해당 자원에 대한 CRUD(Create, Read, Update, Delete) 작업을 HTTP의 기본 명령어인 POST, GET, PUT, DELETE를 통해서 처리한다.
- REST 구조 스타일에 적합한 Web API를 REST API라고 한다.
- URI(Uniform Resource Identifier) 식별자 설계
http://www.slipp.net/wiki/pages/viewpage.action?pageId=12878219

1회 – REST 아키텍쳐에 대한 기본(DRAFT)
한마디로 REST를 정리하면 HTTP URI + HTTP Method 이다. URI로 대상 자원을 명시하고 Method로 해당 자원에 대한 행위를 정의한다.
http://bcho.tistory.com/321

REST API 설계와 구현 (A부터 I까지)
​REST = Resource(20&) + URI(70%) + HTTP method(10%)
REST Architecture 6가지 원칙
- 균일한 인터페이스 Uniform interface
- 상태없음 Stateless
- 캐시 Cache
- 클라이언트/서버 Client/Server
- 계층 시스템 Layered system
- (조건부) Code on demand
http://seminar.eventservice.co.kr/JCO_1/images/track4-1.pdf

REST API 설계 // Speaker Deck
​Archirectural Styles
- Client-Server
- Stateless
- Cache
- Uniform Interface
- Layered System
- Code-On-Demand
https://speakerdeck.com/leewin12/rest-api-seolgye

REST API Tutorial
http://www.restapitutorial.com/lessons/whatisrest.html

[C#] REST API 만들기
http://reqres.tistory.com/archive/20140213

NDC14 범용 게임 서버 프레임워크 디자인 및 테크닉
http://www.slideshare.net/iFunFactory/20140524-ndc-sharing#btnNext

조이시티 모바일 서비스에서의 REST API 와 인증방식에 대한 고민
http://stunstun.tistory.com/54

The OAuth 1.0 Protocol
http://tools.ietf.org/html/rfc5849

[Node.js] Node.js, Express, MongoDB를 이용하여 REST API 만들기
http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/
http://mobicon.tistory.com/197


사례

REST API 개발가이드 — Kakao Developers
https://developers.kakao.com/docs/restapi

The Twitter REST API | Twitter Developers
https://dev.twitter.com/docs/api

API Reference - Google Play Game Services
https://developers.google.com/games/services/web/api/

MSDN 서버 쪽 시나리오
http://msdn.microsoft.com/ko-kr/library/hh243649.aspx

소셜앱:(중급) (암산왕) 소셜앱스 개발 A to Z
http://gamedev.naver.com/index.php/%EC%86%8C%EC%85%9C%EC%95%B1:(%EC%A4%91%EA%B8%89)_(%EC%95%94%EC%82%B0%EC%99%95)_%EC%86%8C%EC%85%9C%EC%95%B1%EC%8A%A4_%EA%B0%9C%EB%B0%9C_A_to_Z

모바게 RESTful API 사용방법
https://docs.mobage.com/display/KRSA/How_to_use_the_RESTful_API_Unity





CJ 넷마블 LOG적용 때 사용했던 Unity3d RESTAPI 코드 (일부)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public void Send(string sI_LogId = "",string sI_LogDetailId  = "")
    {        
        sBodyCenter = sBodyCenter.Remove(sBodyCenter.Length - 1);
        
        string sBodyTop = 
            "{"
            +"\"I_GameCode\":"
            + "\"" +  sGameCode + "\","
            +"\"I_LogId\":"
            + sI_LogId
            +",\"I_LogDetailId\":"
            + sI_LogDetailId
            +",\"I_ChannelUserId\":"
            + "\"" + GetKaKaoID() + "\"" //string
            +",\"I_PCSeq\":"
            + "\"" + GetPCSeq() + "\"" //string
                +",\"I_LogDes\":";        
                
        string sGetIP = "";
        
        sGetIP = GetIP();
        
        string sBodybottom =
            "\"I_ConnectIP\":"
                + "\"" + sGetIP + "\""                
                + "}";
               
        sBodyCenter += "},";        
        
        string input = sBodyTop + sBodyCenter + sBodybottom;
        
        var form = new WWWForm();    
        form.AddField("destination","netmarble.mobile.gameLog");         
        form.AddField("gamecode","dawn");        
        form.AddField("body",input);
        
        Hashtable headers = new Hashtable();
        headers.Add("Content-Type""application/x-www-form-urlencoded");
           
        var rawData = form.data;
            
        string CJServer = "http://gamelog.netmarble.net"
        
        // CJSeverSetting
        WWW www = new WWW(CJServer, rawData, headers);        
        
        StartCoroutine(WaitForRequest(www));
        
        sBodyTop = null;
        sBodyCenter =  null;
        sBodybottom = null;
    }
 
IEnumerator WaitForRequest(WWW www)
 {
     yield return www;
 }



Unity3D 에서 REST API 사용예제 (클라이언트 관점, SHA256 암호화)
http://forum.unity3d.com/threads/using-rest-api-with-httpwebrequest-to-an-azure-blob-store.227494/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using UnityEngine;
using System.Security.Cryptography;
using System.Xml.Linq;
using System.Globalization;
using System.Collections;
using System.Text;
using System.Net;
using System.IO;
using System;
 
public class DatabaseClient : MonoBehaviour {
 
    string accessKey = "myAccessKeyFromAzureStorageManageAccessKey==";
    string accountName = "accountName";
    string container = "test"//Storage container created on azure portal called "test"
 
    // Use this for initialization
    void Start () {
        GetBlob_Test();
    }
   
    // Update is called once per frame
    void Update () {
   
    }
 
    // GetBlob_Test
    void GetBlob_Test()
    {
        Debug.Log ("Attempting to GET from server");
        DateTime dt = DateTime.UtcNow;
 
        string stringToSign = String.Format("GET\n"
                                            + "\n" // content md5
                                            + "\n" // content type
                                            + "x-ms-date:" + dt.ToString("R") + "\nx-ms-version:2012-02-12\n" // headers
                                            + "/{0}/{1}\ncomp:list\nrestype:container", accountName, container);
 
        string authorizationKey = SignThis(stringToSign, accessKey, accountName);
        string method = "GET";
        string urlPath = string.Format("https://{0}.blob.core.windows.net/{1}?restype=container&comp=list"
        accountName, container);
        Uri uriTest = new Uri(urlPath);
 
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create (uriTest);
        request.Method = method;
        request.Headers.Add("x-ms-date", dt.ToString("R"));
        request.Headers.Add("x-ms-version""2012-02-12");
        request.Headers.Add("Authorization", authorizationKey);
 
        Debug.Log ("Authorization: " + authorizationKey);
 
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            Debug.Log("Response = " + response);
        }
    }
 
    private static String SignThis(String StringToSign, string Key, string Account)
    {
        String signature = string.Empty;
        byte[] unicodeKey = Convert.FromBase64String(Key);
        using (HMACSHA256 hmacSha256 = new HMACSHA256(unicodeKey))
        {
            Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(StringToSign);
            signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
        }
       
        String authorizationHeader = String.Format(
            CultureInfo.InvariantCulture,
            "{0} {1}:{2}",
            "SharedKeyLite",
            Account,
            signature);
       
        return authorizationHeader;
    }
}

댓글 없음 :

댓글 쓰기