본문 바로가기

프로그래밍/API

구글 GData API 프로토콜 기본. Google Data APIs Protocol Basics

 출처 : http://code.google.com/apis/gdata/basics.html

예> /myFeed 라는 피드가 있다고 가정한다. 내용은 없다.

 

피드 요청하기
서버에 request 를 보낸다.

GET /myFeed

서버응답

200 OK

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Foo</title>
  <updated>2006-01-23T16:25:00-08:00</updated>
  <id>http://www.example.com/myFeed</id>
  <author>
    <name>Jo March</name>
  </author>
  <link href="/myFeed" rel="self"/>
</feed>

 

타이틀, 작성자 이름등의 메타데이터만 있다.

 

새 게시물을 넣기

 

POST /myFeed
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>Elizabeth Bennet</name> 
    <email>liz@gmail.com</email> 
  </author>
  <title type="text">Entry 1</title>
  <content type="text">This is my entry</content>
</entry>


id,link,updated 는 없고, 이름,이메일등만 넣었다.

서버응답

201 CREATED

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>1</id>
  <link rel="edit" href="http://example.com/myFeed/1/1/"/>
  <updated>2006-01-23T16:26:03-08:00</updated>
  <author>
    <name>Elizabeth Bennet</name>
    <email>liz@gmail.com</email>
  </author>
  <title type="text">Entry 1</title>
  <content type="text">This is my entry</content>
</entry>


문자열 찾기

GET request에 q 파라미터를 보내서 문자열을 찾는다.

 

GET /myFeed?q=This

 

서버응답.

 

200 OK

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Foo</title>
  <updated>2006-01-23T16:26:03-08:00</updated>
  <id>http://www.example.com/myFeed</id>
  <author>
    <name>Jo March</name>
  </author>
  <link href="/myFeed" rel="self"/>
  <entry>
    <id>1</id>
    <link rel="edit" href="http://example.com/myFeed/1/1/"/>
    <updated>2006-01-23T16:26:03-08:00</updated>
    <author>
      <name>Elizabeth Bennet</name>
      <email>liz@gmail.com</email>
    </author>
    <title type="text">Entry 1</title>
    <content type="text">This is my entry</content>
  </entry>
</feed>

 

Entry 업데이트.

 

put 을 이용해서, 업데이트를 한다. 만약 파이어월등에서 put을 허가하지 않으면, HTTP post를 이용하고, 헤더에

 

X-HTTP-Method-Override: PUT

 

를 세팅한다.

"This is my entry"에서 "This is my first entry"로 업데이트

 

PUT /myFeed/1/1/

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>1</id>
  <link rel="edit" href="http://example.com/myFeed/1/1/"/>
  <updated>2006-01-23T16:28:05-08:00</updated>
  <author>
    <name>Elizabeth Bennet</name>
    <email>liz@gmail.com</email>
  </author>
  <title type="text">Entry 1</title>
  <content type="text">This is my first entry.</content>
</entry>


서버응답

 

200 OK

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>1</id>
  <link rel="edit" href="http://example.com/myFeed/1/2/"/>
  <updated>2006-01-23T16:28:05-08:00</updated>
  <author>
    <name>Elizabeth Bennet</name>
    <email>liz@gmail.com</email>
  </author>
  <title type="text">Entry 1</title>
  <content type="text">This is my first entry.</content>
</entry>

 

Entry 삭제

삭제를 위해서는 delete request 를 이용. delete를 허용하지 않을 시 HTTP post를 이용. 헤더에,

 X-HTTP-Method-Override: DELETE

을 삽입한다.

삭제방법

DELETE /myFeed/1/2/

서버응답

200 OK


 

 

이 글은 스프링노트에서 작성되었습니다.