Giter Site home page Giter Site logo

fastapi's Introduction

foodiary ๐Ÿ“”๐Ÿ•๐Ÿ”๐ŸŸ๐ŸŒญ

1. ํ”„๋กœ์ ํŠธ ์ •์˜

๐Ÿ‘ง ์ธ๋ ฅ๊ตฌ์„ฑ

  • ๊ฐœ์ธํ”„๋กœ์ ํŠธ

๐Ÿช„ ํ”„๋กœ์ ํŠธ ๋ชฉ์ 

  • ์Œ์‹์„ ๋จน๊ธฐ ์ „ ์‚ฌ์ง„ ํ™œ์˜์„ ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ๋งŽ๋‹ค.
    ํ•˜์ง€๋งŒ ์ด๋•Œ ์ดฌ์˜ํ•œ ์‚ฌ์ง„์„ ๋งค๋ฒˆ ๊ฒŒ์‹œํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ๋“œ๋ฌผ๊ณ  ์Šคํ† ๋ฆฌ์— ์˜ฌ๋ฆฐ ์‚ฌ์ง„์€ ํ•˜๋ฃจ๋ฉด ๋‚ด๋ ค๊ฐ„๋‹ค.
    ๋˜ํ•œ ๊ฐค๋Ÿฌ๋ฆฌ ์ •๋ฆฌ์— ๋ถ€์ง€๋Ÿฐํ•˜์ง€ ์•Š์€ ์‚ฌ๋žŒ๋“ค์€ ๊ฐค๋Ÿฌ๋ฆฌ์—์„œ ๋‹ค์‹œ ์ฐพ์•„๋ณด๊ธฐ๋„ ํž˜๋“ค๋‹ค.
    ์ธ์Šคํƒ€๊ทธ๋žจ๊ณผ ๊ฐ™์€ ์†Œ์…œ ๊ธฐ๋Šฅ์ด ๋“ค์–ด๊ฐ€์ง€ ์•Š์€ ๊ธฐ๋ก์šฉ ์•ฑ์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

โš™๏ธ ํ™˜๊ฒฝ

  • python3.10
  • Framework : FastAPI
  • Database : Mysql + Pymysql + Sqlalchemy + alembic
  • OS : window

2. ๊ธฐ๋Šฅ

  • ๋กœ๊ทธ์ธ & ๋กœ๊ทธ์•„์›ƒ
  • ์Œ์‹ ์‚ฌ์ง„ ์ผ๊ธฐ์žฅ

3. ์‚ฌ์šฉ ๊ธฐ์ˆ 

3.1 stack ๐Ÿ”ง

3.2 tool โš™

4. ๊ฐœ๋ฐœ์ผ์ง€

  • 2022-11-03 fast api project start
  • 2022-11-04 JWT ํ† ํฐ ์ฟ ํ‚ค๋กœ ๋ฐ›์•„์˜ค๋Š” ๋ฐฉ๋ฒ• ์ฐพ๊ธฐ
  • 2022-11-05 ์ฟ ํ‚ค์— ๋‹ด๊ณ , ๋กœ๊ทธ์ธ ์œ ์ง€๊ฐ€ dependency ์ถ”๊ฐ€, refactoring
  • 2022-11-16 post ๋ชจ๋ธ, ์Šคํ‚ค๋งˆ ์ถ”๊ฐ€
  • 2022-11-17 post list, retrieve ์ถ”๊ฐ€
  • 2022-11-22 food ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ + cors issue
  • 2022-11-23 food ์ด๋ฏธ์ง€ ๊ธฐ๋Šฅ post๋กœ ์ด๋™, ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ, ์ด๋ฏธ์ง€ response ์ถ”๊ฐ€
  • 2022-11-24 food & post ๋ณ‘ํ•ฉ, url ์ˆ˜์ •

5. URL

5.1 auth_router URL

CRUD HTTP URL
ํ† ํฐ ๋ฐœํ–‰ POST /auth/token
๋กœ๊ทธ์ธ POST /auth/login
๋กœ๊ทธ์•„์›ƒ GET /auth/logout
์œ ์ € ์กฐํšŒ GET /auth/users
์œ ์ € ์ƒ์„ฑ POST /auth/users
๋‚ด ์ •๋ณด ์กฐํšŒ GET /auth/me

5.2 food_router URL

CRUD HTTP URL
๊ฒŒ์‹œ๊ธ€ ์ „์ฒด ์กฐํšŒ GET /food
๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ POST /food
ํŠน์ • ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ GET /food/{food_id: int}
์ด๋ฏธ์ง€ ๋“ฑ๋ก POST /food/img
๊ฒŒ์‹œ๊ธ€ ์ด๋ฏธ์ง€ ์กฐํšŒ GET /food/img/{post_id: int}

6. UML

6.1 ๊ฒŒ์‹œ๊ธ€ ๋“ฑ๋ก ์‹œํ€€์Šค ๋‹ค์ด์–ด๊ทธ๋žจ

6.2 ๋กœ๊ทธ์ธ ์‹œํ€€์Šค ๋‹ค์ด์–ด๊ทธ๋žจ

7. Database

7.1 Mysql DB ์‚ฌ์šฉ

7.2 Alembic

  • model ๋ณ€ํ™”๋ฅผ Alembic์œผ๋กœ DB์— ์ ์šฉ

8.Trouble Shooting

8.1 ๊ฒŒ์‹œ๊ธ€ ๋“ฑ๋ก ์‹œ ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฌธ์ œ

  • PostBase ์Šคํ‚ค๋งˆ์— ์ด๋ฏธ์ง€ ํŒŒ์ผ๊ณผ ํ…์ŠคํŠธ๋ฅผ ๋™์‹œ์— ์ž…๋ ฅ ํ•  ๋•Œ์— ์˜ค๋ฅ˜ ๋ฐœ์ƒ
  • ๊ฒŒ์‹œ๊ธ€์„ ๋“ฑ๋ก ํ•  ๋•Œ์— title, description ์ž…๋ ฅ๊ณผ ์ด๋ฏธ์ง€ ๋“ฑ๋ก ๋ถ„๋ฆฌ
  • url ์š”์ฒญ์„ ํ†ตํ•ด ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
@router.post("/img")
async def upload_img(request: Request, post_id: int, file: UploadFile, db: Session = Depends(get_db), dependencies=Depends(AuthProvider())):
   
    contents = await file.read()
    with open(os.path.join(IMG_URL, file.filename), "wb") as fp:
        fp.write(contents)
    return post_crud.update_img(request=request, db=db, post_id=post_id, img_url=file.filename)
    

fastapi's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.