개발로 자기계발
728x90
SMALL
article thumbnail
FastAPI Post Request - 09
Develop/FastAPI 2022. 12. 22. 09:15

1. POST 데이터 생성 DB 저장 ​ 2. dictionary 정의 BOOKS = { 'book_1': {'title':'Title One','author':'Author One'}, 'book_2': {'title':'Title Two','author':'Author Two'}, 'book_3': {'title': 'Title Three', 'author': 'Author Three'}, 'book_4': {'title': 'Title Four', 'author': 'Author Four'}, 'book_5': {'title': 'Title Five', 'author': 'Author Five'}, } 3. 함수 정의 @app.post("/") async def create_book(book_tit..

article thumbnail
FastAPI Query Parameters - 08
Develop/FastAPI 2022. 12. 22. 09:12

1. dictionary 정의 BOOKS = { 'book_1': {'title':'Title One','author':'Author One'}, 'book_2': {'title':'Title Two','author':'Author Two'}, 'book_3': {'title': 'Title Three', 'author': 'Author Three'}, 'book_4': {'title': 'Title Four', 'author': 'Author Four'}, 'book_5': {'title': 'Title Five', 'author': 'Author Five'}, } 2. 함수안에 매개변수 정의 skip_book은 string을 받고 Default 값으로 book_3으로 지정한다. new_books라는 ..

article thumbnail
FastAPI Path Parameters(추가) - 07
Develop/FastAPI 2022. 12. 21. 14:55

1. dictionary 정의 BOOKS = { 'book_1': {'title':'Title One','author':'Author One'}, 'book_2': {'title':'Title Two','author':'Author Two'}, 'book_3': {'title': 'Title Three', 'author': 'Author Three'}, 'book_4': {'title': 'Title Four', 'author': 'Author Four'}, 'book_5': {'title': 'Title Five', 'author': 'Author Five'}, } 2. 함수 정의 전체 BOOKS의 list를 볼 수 있음 @app.get("/") async def read_all_books(): ret..

article thumbnail
FastAPI Path Parameters(열거형) - 06
Develop/FastAPI 2022. 12. 21. 14:19

1. Enum 모듈을 삽입 사전에 정해진 범위에 값이 있을 때 사용 from enum import Enum ​ 2. 새로운 클래스를 생성 Enums 상속 str 상속 -> 내부 클래스 변수들은 string 형식이라고 명 class DirectionName(str, Enum): north = "North" south = "South" east = "East" west = "West" 3. Path Parameters(경로 매개변수) url에서 값을 받음 @app.get("/directions/{direction_name}") async def get_direction(direction_name: DirectionName): if direction_name == DirectionName.north: retu..

article thumbnail
FastAPI 요청 메서드 로직 - 05
Develop/FastAPI 2022. 12. 21. 14:07

1. CRUD Operations Create - 생성 Read - 호출 Update - 업데이트 Delete - 삭제 2. Use HTTP Request Method GET - 호출 PUT - 업데이트 POST - 생성 DELETE - 삭제 ex) book GET - get all the books PUT - Update book POST - Create new book DELETE - Delete book 3. 딕셔너리 만들어서 GET 호출하기 from fastapi import FastAPI app = FastAPI() BOOKS = { 'book_1': {'title':'Title One','author':'Author One'}, 'book_2': {'title':'Title Two','auth..

article thumbnail
FastAPI Swagger / HTTP 데코레이터 - 04
Develop/FastAPI 2022. 12. 21. 13:20

1. FastAPI 실행 uvicorn {파일이름.py}:app --reload ​ 2. FastAPI OpenAPI http://127.0.0.1:8000/openapi.json Swagger UI http://127.0.0.1:8000/docs CURL이란? = Client URL - 클라이언트에서 커맨드 라인이나 소스코드로 손 쉽게 웹 브라우저 처럼 활동할 수 있도록 해주는 기술 -i: 응답 헤더 출력 (옵션 없으면 응답 본문만 출력함) -v: 중간 처리 과정, 오류 메시지, 요청 메시지와 응답 메시지를 헤더와 본문을 포함해 전체 출력 -X: 요청 메소드를 지정 (옵션 없으면 기본값은 GET) -H: 요청 헤더를 지정 -d: 요청 본문을 지정 (옵션 없으면 요청 본문 없음) 출처 - https://..

article thumbnail
FastAPI - Swagger, HTTP 요청 관련 - 03
Develop/FastAPI 2022. 12. 20. 00:19

실무에서 FastAPI를 채택 하는 이유(문서 자동화) FastAPI는 OpenAPI를 채택하고 있어, 이를 기반으로 자신의 코드를 읽어 OpenAPI 규격에 맞는 json 파일을 만들어주기 때문에 백엔드 엔지니어가 문서 작업에 할애하는 시간을 줄일 수 있다. 1. OpenAPI란? OpenAPI 또는 OpenAPI Specification(OAS)라고 부름 RESTful API를 기 정의된 규칙에 맞게 API spec을 json이나 yaml로 표현하는 방식 2. OpenAPI Document Defines Schema Data Format Data Type Path Object And much more 2. View OpenAPI Schema FastAPI는 OpenAPI Schema를 생성 애플리케이..

article thumbnail
FastAPI 설정 및 설치 - 02
Develop/FastAPI 2022. 12. 20. 00:09

사용 기기 : Mac / 사용 툴: Pycharm ​ 1. 가상환경 설정​하기 프로젝트에 대한 라이브러리 관리가 쉽다 컴퓨터 내에 무분별하게 설치 되는 것을 막을 수 있음. 2. 가상환경 설치(직접 설치시) pip install virtualenv(python3.3 이전에 사용 되던 라이브러리) -m venv {가상환경폴더} ex) -m venv venv / -m venv fastapienv 3. 가상환경 활성화 source {가상환경폴더}/bin/activate 가상환경 비활성화 source deactivate​ 4. FastAPI 설치하기 pip3 install fastapi[all](한번에 설치) or pip install fastapi pip install uvicorn uvicorn : 웹 서버..

article thumbnail
FastAPI 란? - 01
Develop/FastAPI 2022. 12. 20. 00:04

"FastAPI는 표준 파이썬 타입 힌트를 바탕으로 한 파이썬 3.6이상에서 작동하는, 현대적이고 빠른(고성능) API 서버 웹 프레임워크다." ​ FastAPI 장점 및 특징 빠름: (Starlette과 Pydantic 덕분에) NodeJS 및 Go와 대등할 정도로 매우 높은 성능. 사용 가능한 가장 빠른 파이썬 프레임워크 중 하나. 빠른 코드 작성: 약 200%에서 300%까지 기능 개발 속도 증가. 적은 버그: 사람(개발자)에 의한 에러 약 40% 감소. 직관적: 훌륭한 편집기 지원. 모든 곳에서 자동완성. 적은 디버깅 시간. 쉬움: 쉽게 사용하고 배우도록 설계. 적은 문서 읽기 시간. 짧음: 코드 중복 최소화. 각 매개변수 선언의 여러 기능. 적은 버그. 견고함: 준비된 프로덕션 용 코드를 얻으십..

728x90
SMALL