얼마 전에 어떤 회사에 인터뷰를 하러 간 적이 있었다.
당시 그 회사는 자체 솔루션을 개발할 기술인력을 찾고 있었고 내부적으로 OData를 사용한다고 했다. 좀 창피한 이야기일 수도 있지만 나름 기술적인 부분에서는 많은 정보를 가지고 있다고 했던 것이 무색하게 OData란 단어를 그 회사 사장님에게서 처음 들었다.
작고, 단순한 사이트들만을 계속해서 작업을 하다 보니 어느덧 큰 줄기들을 잃어버린 것을 느끼기 시작했다. 명색이 개발이 좋고, 기술적인 기반을 만들려고 하는 인간이 단어조차도 모른다는 것은 있을 수 없는 것이라서 다시 새로운 단어들과 개념들을 알아보는 시간을 가지려고 한다.
OData (Open Data Protocol) 란?
서비스 제공자 입장에서는 웹으로 데이터를 제공하는 방식으로 각 포탈 사이트들이 제공하는 OPEN API 포맷을 독자적인 형식이 아니라 오픈된 공통규약으로 제공 가능하며, 개발자는 이 정보를 다양한 언어의 클라이언트 라이브러리로 어플리케이션에서 소비할 수 있도록 사용하면 된다.
공식 사이트는 www.odata.org 이며 많은 언어들을 지원하고 있다.
좀더 상세하게 정의를 해 보면 OData는 Atom Publishing Protocol (RFC4287) 의 확장 형식이고 REST (REpresentational State Transfer) Protocol 이다. 따라서 웹 브라우저에서 OData 서비스로 노출된 데이터를 볼 수 있다. 그리고 AtomPub 의 확장이라고 했듯이 데이터의 조회만으로 한정되는 것이 아니라 CRUD 작업이 모두 가능하다.
Example
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<service xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app" xml:base="http://services.odata.org/Website/odata.svc/">
<workspace>
<atom:title>Defaultatom:title>
<collection href="ODataConsumers">
<atom:title>ODataConsumersatom:title>
collection>
<collection href="ODataProducerApplications">
<atom:title>ODataProducerApplicationsatom:title>
collection>
<collection href="ODataProducerLiveServices">
<atom:title>ODataProducerLiveServicesatom:title>
collection>
workspace>
service>
위와 같은 결과를 볼 수 있을 것이다. 이 결과는 OData에서 workspace라고 부르는 Entity Sets (Feeds) 리스트를 보여주는 것이다.
위의 리스트들 중에서 ODataConsumers라는 데이터 컬렉션을 확인해 보기 위해서 http://services.odata.org/website/odata.svc/ODataConsumers 로 URL을 변경해 보도록 한다. (ODataConsumers라는 정보는 REST로 전달되는 정보이므로 대/소문자를 구분해야 한다)
xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://services.odata.org/Website/odata.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">ODataConsumerstitle>
<id>http://services.odata.org/website/odata.svc/ODataConsumersid>
<updated>2013-08-10T06:20:56Zupdated>
<link rel="self" title="ODataConsumers" href="ODataConsumers" />
<entry>
<id>http://services.odata.org/Website/odata.svc/ODataConsumers(1)id>
<title type="text">Browserstitle>
<summary type="text">Most modern browsers allow you to browse Atom based feeds. Simply point your browser at one of the OData Producers.summary>
<updated>2013-08-10T06:20:56Zupdated>
<author>
<name />
author>
<link rel="edit" title="ODataConsumer" href="ODataConsumers(1)" />
<category term="ODataServices.ODataConsumer" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">1d:Id>
<d:Name m:type="Edm.String">Browsersd:Name>
<d:Description m:type="Edm.String">Most modern browsers allow you to browse Atom based feeds. Simply point your browser at one of the OData Producers.d:Description>
<d:ApplicationUrl m:type="Edm.String">d:ApplicationUrl>
m:properties>
content>
entry>
...
<entry>
<id>http://services.odata.org/Website/odata.svc/ODataConsumers(14)id>
<title type="text">(Unofficial) SSIS import scripttitle>
<summary type="text">A SQL Server Integration Services script for importing OData into SQL Server.summary>
<updated>2013-08-10T06:20:56Zupdated>
<author>
<name />
author>
<link rel="edit" title="ODataConsumer" href="ODataConsumers(14)" />
<category term="ODataServices.ODataConsumer" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">14d:Id>
<d:Name m:type="Edm.String">(Unofficial) SSIS import scriptd:Name>
<d:Description m:type="Edm.String">A SQL Server Integration Services script for importing OData into SQL Server.d:Description>
<d:ApplicationUrl m:type="Edm.String">http://www.cozyroc.com/script/odata-sourced:ApplicationUrl>
m:properties>
content>
entry>
feed>
위의 결과와 같이 ODataConsumers 의 구성 Entity 들을 확인할 수 있다.
내용을 잠시 확인해 보면 entry 는 ID 로 유일하게 식별할 수 있는 URL 값을 가지고 있고, 그 외에 몇 가지 속성들을 가지고 있는 것을 볼 수 있다. 가장 중요한 부분은 “content” 로 표준 엔터티 데이터 모델 (EDM – Entity Data Model) 을 가지고 있다.
Queries
예를 들어 Consumer 들 중에서 최 상위 3명 만을 추출하고 싶은 경우는 다음과 같이 URL을 정의하면 된다.
http://services.odata.org/website/odata.svc/ODataConsumers?$top=3
$top 연산자는 상위 몇 개를 골라는 내는 것이고 그 밖에는 아래와 같이 대표적인 연산자들이 존재한다.
Query String
|
Description
|
Sample
|
$skip= | 처음 n개를 생략하고 나머지를 반환한다. | http://services.odata.org/website/odata.svc/ODataConsumers?$skip=5 |
$orderBy= | 지정한 속성을 기준으로 정렬하여 반환한다. | http://services.odata.org/website/odata.svc/ODataConsumers?$orderby=Name |
$filter= | 필터 표현에 따라서 필터링된 결과를 반환한다. (<, >, == 등에 대한 특수문자 처리 필요) | http://services.odata.org/website/odata.svc/ODataConsumers?$filter=Id%20gt%203 |
물론 더 많은 연산자들이 존재한다. http://www.odata.org/developers/protocols/uri-conventions#QueryStringOptions 를 찾아보면 된다.
Updates
Http Verbs 는 “GET” – Reading, “PUT” – Creating, “POST” – Update, “DELETE” – Delete 으로 처리가 된다.
JSON
언제 사용하는 것이 좋을까?
우선 OData는 표준이라는 점이고, 외부 업체나 증가될 가능성이 있는 기타 다양한 클라이언트들을 대상으로 처리하는 경우에 적합하고, 닷넷의 입장에서 보면 이미 .NET Framework에 연계되어 있기 때문에 클라이언트에서 LINQ 등을 사용할 수 있고, EXCEL 2010 의 Pivot 테이블처리에서 인식이 가능하다.
또한 일반적인 Web Service 환경에서 Get
가장 큰 이점은 하나의 OData 를 구성해 놓으면 클라이언트가 다양하게 조건들을 변형(URL) 해서 사용할 수 있다는 것이다.
좋은 자료 감사합니다!
답글삭제도움이 되셨기를 바랍니다. ^^
삭제오늘도 좋은 하루 되세요.
저도 실무자인데 OData 를 parameter상에서 보기만 했을 뿐 "저게 뭘까" 하고는 한참이 지나서야 찾아보게 되었네요 덕분에 잘 배우고 갑니다
답글삭제좋은 포스팅 잘보고갑니다~
상용 컴포넌트 사용하다 보게되어 찾다보니 여기까지 왔네요~ 너무 쉬운 설명으로 대략적으로나마 감이 오는 것 같습니다.
답글삭제감사합니다!
좋은글 너무 잘 보고 갑니다 ! 감사합니다.
답글삭제좋은글 잘 보고 갑니다!
답글삭제