• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

삭제 api 관련 질문입니다.

20.03.09 00:18 작성 조회수 263

5

학습노트 조회 / 생성은 저 슬래쉬가 들어가는데

삭제는 그냥 인자값만 주는 이유가 있나요?

api 문서에도 

GET​/posts
<button class="authorization__btn unlocked" aria-label="authorization button unlocked" style="box-sizing:inherit;font-family:sans-serif;font-size:16px;line-height:1.15;margin:0px;overflow:visible;text-transform:none;-webkit-appearance:button;cursor:pointer;outline:none;padding:0px 10px;border:none;background:none;opacity:0.4"><svg width="20" height="20"><use href="#unlocked" xlink:href="#unlocked"><svg viewbox="0 0 20 20" id="unlocked"><path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path></svg></use></svg></button>
POST​/posts
<button class="authorization__btn unlocked" aria-label="authorization button unlocked" style="box-sizing:inherit;font-family:sans-serif;font-size:16px;line-height:1.15;margin:0px;overflow:visible;text-transform:none;-webkit-appearance:button;cursor:pointer;outline:none;padding:0px 10px;border:none;background:none;opacity:0.4"><svg width="20" height="20"><use href="#unlocked" xlink:href="#unlocked"><svg viewbox="0 0 20 20" id="unlocked"><path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path></svg></use></svg></button>
GET​/posts​/{_id}
<button class="authorization__btn unlocked" aria-label="authorization button unlocked" style="box-sizing:inherit;font-family:sans-serif;font-size:16px;line-height:1.15;margin:0px;overflow:visible;text-transform:none;-webkit-appearance:button;cursor:pointer;outline:none;padding:0px 10px;border:none;background:none;opacity:0.4"><svg width="20" height="20"><use href="#unlocked" xlink:href="#unlocked"><svg viewbox="0 0 20 20" id="unlocked"><path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path></svg></use></svg></button>
PUT​/posts​/{_id}
<button class="authorization__btn unlocked" aria-label="authorization button unlocked" style="box-sizing:inherit;font-family:sans-serif;font-size:16px;line-height:1.15;margin:0px;overflow:visible;text-transform:none;-webkit-appearance:button;cursor:pointer;outline:none;padding:0px 10px;border:none;background:none;opacity:0.4"><svg width="20" height="20"><use href="#unlocked" xlink:href="#unlocked"><svg viewbox="0 0 20 20" id="unlocked"><path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path></svg></use></svg></button>

이런식으로 다 posts가 붙는데.. delete는 따로 posts를 안붙히는건 그냥 api 규칙인지 알고싶습니다!

답변 1

답변을 작성해보세요.

4

안녕하세요 career87님, 좋은 질문이네요! 말씀하신 것처럼 axios의 API 함수의 규칙 때문에 그렇습니다. 기본적으로 get, post, put, delete API를 사용할 때 첫 번째 인자가 url이기 때문에 인스턴스로 공통 URL을 잡아줬다고 하더라도 일단 `/`을 넘겨야 합니다. 같은 맥락에서 put, delete와 같이 id가 넘어가야 하는 것은 그냥 id만 넘겨도 됩니다 ㅎㅎ