TIL35 | Westagram - API Spec & URL Design

2021. 10. 27. 08:56프로그래밍/웹관련

반응형

westagram 프로젝트를 진행하며

궁금했던 사항들과 고민했던 내용들을 글로 적어보며 생각을 정리한 글

 

 

Postings - API Spec & URL

Posting Model

{
    user,      
    content,   
    url,       
    created_at,
    updated_at
}

GET /postings

  • get all postings
http -v GET 127.0.0.1:8000/postings
# Response 200
{
    [posting, posting, ....]
}

POST /postings

  • creating new posting
http -v POST 127.0.0.1:8000/postings content='' url=''
# Response 201
{
    posting # 현재는 success
}

GET /postings/:id

  • get posting by id
http -v GET 127.0.0.1:8000/postings/id
# Response 200
{
    posting # 현재는 success
}

PUT /postings/:id

  • updating posting
http -v PUT 127.0.0.1:8000/postings/id content='' url=''
# Response 200
{
    posting
}

DELETE /postings/:id

  • deleting posting
http -v DELETE 127.0.0.1:8000/postings/id
# Response 204

 

Comments - API Spec & URL

Comment Model

{
    user,      
    posting,
    content,   
    created_at,
    updated_at
}

GET /comments

  • get all comments
http -v GET 127.0.0.1:8000/postings/id/comments
# Response 200
{
    [comments, posting, ....]
}

POST /comments

  • creating new comments
http -v POST 127.0.0.1:8000/postings/id/comments content=''
# Response 201
{
    posting # 현재는 success
}

GET /comments/:id

  • get comment by id
http -v GET 127.0.0.1:8000/postings/id/comments/c_id
# Response 200
{
    comment # 현재는 success
}

PUT /comments/:id

  • updating comment
http -v POST 127.0.0.1:8000/postings/p_id/comments/c_id content=''
# Response 200
{
    comment
}

DELETE /comments/:id

  • deleting comment
http -v DELETE 127.0.0.1:8000/postings/id/comments/c_id
# Response 204

 

질문 사항

  1. View class 표기법

    • Naming convention for Django URL, View
    • View class에 get, post, pust, delete 등 http method 이름 사용하는지?

    => Nope@!

  2. Router

    • 127.0.0.1:8000/postings/1
    • 127.0.0.1:8000/postings/1/comments
    • 127.0.0.1:8000/postings/1/comments/1

    => REST API 디자인이므로 이렇게 사용하는 것이 맞음.

  3. Like 구현

    • 이력관리 ? => 굳이 안해도 됨.
    • URL : 127.0.0.1:8000/postings/1/like?:like
  4. Authorization middleware => posting, comment, like

    • middleware와 decorator의 차이

    => middleware는 전역으로 사용하는 로직

    ​ 로그인 확인 decorator는 전역으로 쓰긴한다. (core > utils.py)

  5. bcrypt salt()

    • 인증 & 인가 세션 중 "사용된 salt 값은 나중에 비밀번호 일치를 확인하기 위해 같이 저장된다."
반응형