{"id":25123146,"url":"https://github.com/f-lab-edu/fastapi-server","last_synced_at":"2025-04-02T16:32:59.965Z","repository":{"id":219293317,"uuid":"748513954","full_name":"f-lab-edu/fastapi-server","owner":"f-lab-edu","description":"FastAPI로 게시글을 생성, 조회, 수정, 삭제할 수 있는 REST API 서버","archived":false,"fork":false,"pushed_at":"2024-04-24T04:01:40.000Z","size":197,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T07:16:03.593Z","etag":null,"topics":["fastapi","poetry","pyenv","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f-lab-edu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-01-26T06:20:49.000Z","updated_at":"2024-04-24T04:01:43.000Z","dependencies_parsed_at":"2024-04-23T08:29:57.009Z","dependency_job_id":null,"html_url":"https://github.com/f-lab-edu/fastapi-server","commit_stats":null,"previous_names":["f-lab-edu/fastapi-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lab-edu%2Ffastapi-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lab-edu%2Ffastapi-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lab-edu%2Ffastapi-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lab-edu%2Ffastapi-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f-lab-edu","download_url":"https://codeload.github.com/f-lab-edu/fastapi-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246851805,"owners_count":20844241,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","poetry","pyenv","python3"],"created_at":"2025-02-08T07:16:05.393Z","updated_at":"2025-04-02T16:32:59.921Z","avatar_url":"https://github.com/f-lab-edu.png","language":"Python","readme":"# fastapi-server\n\n## 아키텍처\n```mermaid\nflowchart LR\n    A[main.py] --api 실행--\u003e api[\"`post.py\n    user.py\n    comment.py`\"]\n    api --데이터 요청--\u003e database.py\n    database.py --데이터 조회--\u003e id1[(post.db)]\n```\n\n## 버전 목록\n- python : 3.12.0\n\n## fastAPI 서버 실행 및 종료 방법\n### 1. 설치 방법\n#### (1). git clone으로 레포지토리 다운로드\n```\ngit clone https://github.com/f-lab-edu/fastapi-server.git\n```\n\n#### (2). poetry 가상환경 실행\n```poetry shell```\n\n#### (3). 서버 실행에 필요한 패키지 다운로드\n```poetry install```\n\n#### (4). 환경 변수 파일 생성 : config.yaml\n- config.yaml 위치\n```\n/config.yaml\n```\n\n- config.yaml 내용 예시\n```\nsecret_key: key01234567890\nalgorithm: HS256\naccess_token_expire_days: 1\n```\n\n#### (5). 환경 변수 파일 생성 : .env\n- .env 위치\n```\n/.env\n```\n\n- .env 내용 예시\n```\nDATABASE_URL=\"mysql://user:1q2w3e4r@db/postdb\"\n```\n\n### 2. 서버 실행 방법\n```uvicorn main:app --reload```\n\n### 3. 종료 방법\n#### (1). 서버 종료\n```ctrl + c```\n\n#### (2). poetry 가상환경 종료\n```exit```\n\n## docker image 링크\nhttps://hub.docker.com/r/8bitcrab/fastapi-server\n\n## API 사용 방법 및 결과 예시\n### 게시글 전체 목록 조회 API\n- 사용 예시\n```\ncurl -X 'GET' \\\n  'http://127.0.0.1:8000/api/posts/?page=1' \\\n  -H 'accept: application/json'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"게시글 목록 조회 성공\",\n  \"data\": [\n    {\n      \"post_id\": 1,\n      \"author\": \"admin\",\n      \"title\": \"제목을 입력해주세요\",\n      \"content\": \"내용을 입력해주세요\",\n      \"created_at\": \"2024-03-06T16:49:59.694742\"\n    },\n    {\n      \"post_id\": 2,\n      \"author\": \"user0001\",\n      \"title\": \"가입인사\",\n      \"content\": \"안녕하세요\",\n      \"created_at\": \"2024-03-10T04:07:31.244932\"\n    }\n  ]\n}\n```\n\n### 게시글 생성 API\n- 사용 예시\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/posts/' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"author\": \"user0001\",\n  \"title\": \"가입인사\",\n  \"content\": \"안녕하세요\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"게시글 생성 성공\"\n}\n```\n\n### 게시글 조회 API\n- 사용 예시\n```\ncurl -X 'GET' \\\n  'http://127.0.0.1:8000/api/posts/2' \\\n  -H 'accept: application/json'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"게시글 조회 성공\",\n  \"data\": {\n    \"post_id\": 2,\n    \"author\": \"admin\",\n    \"title\": \"제목을 입력해주세요\",\n    \"content\": \"내용을 입력해주세요\",\n    \"created_at\": \"2024-03-06T16:49:59.694742\"\n  }\n}\n```\n\n### 게시글 수정 API\n- API 사용 시, 로그인 필요\n- 게시글 작성한 본인 혹은 관리자(admin)가 아닐 시 수정 불가\n- 사용 예시\n```\ncurl -X 'PUT' \\\n  'http://127.0.0.1:8000/api/posts/2' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"author\": \"admin02\",\n  \"title\": \"제목 수정합니다\",\n  \"content\": \"내용도 수정했습니다\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"게시글 번호 2 수정 성공\",\n  \"data\": {\n    \"post_id\": 2,\n    \"author\": \"admin\",\n    \"title\": \"string\",\n    \"content\": \"string\",\n    \"created_at\": \"2024-03-06T16:49:59.694742\"\n  }\n}\n```\n\n### 게시글 삭제 API\n- API 사용 시, 로그인 필요\n- 게시글 작성한 본인 혹은 관리자(admin)가 아닐 시 삭제 불가\n- 사용 예시\n```\ncurl -X 'DELETE' \\\n  'http://127.0.0.1:8000/api/posts/2' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"게시글 번호 2 삭제 성공\"\n}\n```\n\n### 게시글에 해당되는 댓글 목록 조회 API\n- API 사용 시, 로그인 필요\n- 사용 예시\n```\ncurl -X 'DELETE'\n    'http://127.0.0.1:8000/api/posts/1'\n    -H 'accept: application/json'\n```\n\n### 유저 생성 API\n- 1. 사용 예시 : 관리자 생성\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/users/' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"user_id\": \"admin0001\",\n  \"password\": \"A1234567890\",\n  \"nickname\": \"관리자\",\n  \"role\": \"admin\"\n}'\n```\n\n- 2. 사용 예시 : 유저 생성\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/users/' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"user_id\": \"user0001\",\n  \"password\": \"A1234567890\",\n  \"nickname\": \"일반사용자\",\n  \"role\": \"member\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"유저 생성 성공\"\n}\n```\n\n### 유저 수정 API\n- API 사용 시, 로그인 필요\n- 유저 본인 혹은 관리자(admin)가 아닐 시 수정 불가\n- 사용 예시\n```\ncurl -X 'PUT' \\\n  'http://127.0.0.1:8000/api/users/admin02' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMzc0NX0.0nGoAuuJuRs66sP2Mxox9RR-yeQHfidd8iDVWc4w4zo' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"password\": \"A1234567890\",\n  \"nickname\": \"닉네임수정\",\n  \"role\": \"admin\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"유저 아이디 admin02 수정 성공\",\n  \"data\": {\n    \"user_id\": \"admin02\",\n    \"password\": \"$2b$12$XmFM8XLgBakzmNc/ZRjonO1.ebjhn5qrlbFOyEJ/PgkMP.SsdL1PW\",\n    \"nickname\": \"닉네임수정\",\n    \"role\": \"admin\"\n  }\n}\n```\n\n### 유저 삭제 API\n- API 사용 시, 로그인 필요\n- 유저 본인 혹은 관리자(admin)가 아닐 시 삭제 불가\n- 사용 예시\n```\ncurl -X 'DELETE' \\\n  'http://127.0.0.1:8000/api/users/user0001' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMzc0NX0.0nGoAuuJuRs66sP2Mxox9RR-yeQHfidd8iDVWc4w4zo'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"유저 아이디 user0001 삭제 성공\"\n}\n```\n\n### 유저가 작성한 게시글 조회 API\n- API 사용 시, 로그인 필요\n- 사용 예시\n```\ncurl -X 'GET' \\\n  'http://127.0.0.1:8000/api/users/admin02/posts/?page=1' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"유저별 작성 게시글 목록 조회 성공\",\n  \"data\": [\n    {\n      \"post_id\": 4,\n      \"author\": \"admin02\",\n      \"title\": \"첫 게시물\",\n      \"content\": \"안녕하세요\",\n      \"created_at\": \"2024-03-10T05:00:29.616600\"\n    }\n  ]\n}\n```\n\n### 유저가 작성한 댓글 조회 API\n- API 사용 시, 로그인 필요\n- 사용 예시\n```\ncurl -X 'GET' \\\n  'http://127.0.0.1:8000/api/users/admin02/comments/?page=1' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"유저별 작성 댓글 조회 성공\",\n  \"data\": [\n    {\n      \"com_id\": 2,\n      \"author_id\": \"admin02\",\n      \"post_id\": 2,\n      \"content\": \"안녕하세요\",\n      \"created_at\": \"2024-03-10T04:52:08.001156\"\n    },\n    {\n      \"com_id\": 3,\n      \"author_id\": \"admin02\",\n      \"post_id\": 2,\n      \"content\": \"반갑습니다\",\n      \"created_at\": \"2024-03-10T04:52:31.157503\"\n    }\n  ]\n}\n```\n\n### 유저 로그인 API\n- 사용 예시\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/users/login' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"user_id\": \"admin0001\",\n  \"password\": \"A1234567890\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE\",\n  \"token_type\": \"bearer\"\n}\n```\n\n### 유저 로그아웃 API\n- API 사용 시, 로그인 필요\n- 사용 예시\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/users/logout' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzNDM4OX0.GdOIgLBqN5sW2Aic2AJJR47RH3shOJMQxsB1qsW6cwo' \\\n  -d ''\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"로그아웃 성공\"\n}\n```\n\n### 댓글 생성 API\n- 사용 예시\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/comments/' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"com_id\": 1,\n  \"author_id\": \"admin02\",\n  \"post_id\": 2,\n  \"content\": \"반갑습니다\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"댓글 생성 성공\"\n}\n```\n\n### 댓글 수정 API\n- API 사용 시, 로그인 필요\n- 댓글 작성한 본인 혹은 관리자(admin)가 아닐 시 수정 불가\n- 사용 예시\n```\ncurl -X 'PUT' \\\n  'http://127.0.0.1:8000/api/comments/1' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"content\": \"댓글 수정했어요\"\n}'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"댓글 아이디 1 내용 수정 성공\",\n  \"data\": {\n    \"content\": \"댓글 수정했어요\"\n  }\n}\n```\n\n### 댓글 삭제 API\n- API 사용 시, 로그인 필요\n- 댓글 작성한 본인 혹은 관리자(admin)가 아닐 시 삭제 불가\n- 사용 예시\n```\ncurl -X 'DELETE' \\\n  'http://127.0.0.1:8000/api/comments/1' \\\n  -H 'accept: application/json' \\\n  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4wMiIsImV4cCI6MTcxMDEzMDc1MH0.JCIdSoqTm6hpxNFnu_vU_RxdZA4v7vChdl2AhiptQFE'\n```\n\n- 결과 예시\n```\n{\n  \"message\": \"댓글 아이디 1 삭제 성공\"\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-lab-edu%2Ffastapi-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff-lab-edu%2Ffastapi-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-lab-edu%2Ffastapi-server/lists"}