# Project 2 Client-Server HTTP API Spec 문서 연락처와 사진을 동기화하는 서버입니다. REST API 아키텍처를 따릅니다. GET 조회 POST 생성 PUT 업데이트 DELETE 삭제 검색할 때 옵션은 'q' parameter에 JSON을 URL encode해서 보냅니다. [논의 필요] 연락처의 경우 연락처 하나를 서버에 추가할 때마다 고유의 key를 부여해줍니다. (중복 여부는 따로 검사하지 않음) 이미지는 이미지에 대해 SHA2 해시를 생성해 중복되지 않는 파일만 s3 따로 업로드하며, 구글 포토처럼 업로드된 파일들의 자체 갤러리를 갖는 형식으로 합니다. (SHA2 해시는 서버에서 생성) ### 참조 [REST-API 한글로 정리된 문서](http://meetup.toast.com/posts/92) ## API Specification ### User Authentication 아직 어떻게 할 지 모르겠음.. 우선 인증 없이 수행 가능하게 만들어야지 방안 1. bearer token 2. oauth 3. amazon cognito <<< 이걸로 할 듯? ### Query in GET database에서 검색할 때 넣을 옵션을 커스텀할 수 있음 현재 /photos와 /music만 지원함 #### Options q로 검색 옵션을 json encoding해서 보냅니다. 특정 metadata.md5를 검색하고 싶으면 {"metadata.md5": "[md5]"}를 인코딩해 q parameter에 올려야 한다 #### Example GET /photos?q={"uuid":"[uuid]"} ### 연락처 정보 **URI : /contacts** GET - 유저 연락처 정보를 가져옵니다 response ```json { "content": [ { "uuid": "[uuid]", "name": "류석영 교수님", "phone": "010-8153-1244", "email": "12312@gmail.com" } ] } ``` POST /contacts - 연락처 업로드 Request body ```json { "content": [ { "name": "류식영 교수님", "phone": "010-8153-1244", "email": "sukyoung.ryu@gmail.com" } ] } ``` Response Body ```json { "result": [ { "msg": "success", "uuid": "[uuid]", "name": "류식영 교수님", "phone": "010-8153-1244", "email": "sukyoung.ryu@gmail.com" } ] } ``` PUT /contacts/:uuid - 연락처 수정 request body ```json { "name": "류식영 교수님", "phone": "010-8153-1244", "email": "sukyoung.ryu@gmail.com" } ``` DELETE /contacts/:uuid - 연락처 삭제 ### 이미지 **URI: /photos** #### 이미지 조회 GET /photos ```json { "content": [ { "uuid": "124gd234", "metadata": { "createdAt": "2017-09-21", "uploadedAt": "2017-10-01", "orientation": 0, "name": "alias-name", "md5": "[md5]" }, "thumbnail": "http://domain/thumb.jpg", "url": "http://s3.amazon.com/12513twd4.jpg" }, { "uuid": "124gd234", "metadata": { "createdAt": "2017-09-21", "uploadedAt": "2017-10-01", "orientation": 90, "name": "ice-bear.jpg", "md5": "[md5]" }, "thumbnail": "http://domain/thumb.jpg", "url": "http://s3.amazon.com/12513twd4.jpg" } ] } ``` #### 이미지 업로드 POST /photos 이미지 파일에 대한 메타데이터와 이미지 데이터를 Multipart Form Data로 보냅니다. md5 해시를 함께 보내주어야 하며 (integrity check) 서버는 해당 데이터를 처리합니다. **Example** POST /photos Request Body --Metadata Field ```json { "metadata": [ { "fileName": "cute-cat-jpg", "createdAt": "2017-08-21", "md5": "[md5 hash for data integrity check]", "name": "your-preferred-name" } ] } ``` --Field of files cute-cat-jpg: [Binary] Response ```JSON { "msg": "success", "result": [ { "fileName": "something", "msg": "success", "uuid": "[uuid]", "url": "[url]" }, { "fileName": "good", "uuid": "[uuid]", "msg": "fail", "reason": "file already exists", } ] } ``` PUT 이미지 파일 metadata 업데이트 PUT /photos/:uuid DELETE 이미지 파일 삭제 DELETE /photos/:uuid ### 음악 **URI : /music** GET - 음악 정보를 가져옵니다 #### Example GET /music response ```json { "content": [ { "uuid": "124gd234", "metadata": { "title": "music title", "artist": "various artists", }, "url": "http://s3.amazon.com/1asdfsd.mp3", "thumbnail_url": "http://s3.amazon.com/1asdfsd.jpg" }, { "uuid": "124gd234", "metadata": { "title": "music title", "artist": "various artists", }, "url": "http://s3.amazon.com/1asdfsd.mp3", "thumbnail_url": "http://s3.amazon.com/1asdfsd.jpg" } ] } ``` #### 음악 업로드 POST /music 메타데이터와 이미지 데이터를 Multipart Form Data로 보냅니다. md5 해시를 함께 보내주어야 하며 (integrity check) 서버는 해당 데이터를 처리합니다. * thumbnail은 없는경우 null, 있는 경우 보내는 파일의 이름을 보냅니다. **Example** POST /music Request Body --Metadata Field ```json { "metadata": [ { "fileName": "some-music-mp3", "title": "music title", "artist": "various artists", "md5": "[md5 hash for data integrity check]", "thumbnail": "some-picture-jpg" } ] } ``` --Field of files some-music-mp3: [Binary] some-picture-jpg: [Binary] Response ```JSON { "msg": "success", "result": [ { "msg": "success", "uuid": "[uuid]", "url": "[url]", "thumbnail_url": "[url]" }, { "fileName": "good", "uuid": "[uuid]", "msg": "fail", "reason": "file already exists", } ] } ``` PUT metadata 업데이트 PUT /music/:uuid DELETE 음악 파일 삭제 DELETE /music/:uuid ## License Copyright © 2017 FIXME