This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9d6810a
Showing
30 changed files
with
853 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APP_HOST = '0.0.0.0' | ||
APP_PORT = 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* linguist-detectable=false | ||
*.yml linguist-detectable=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__pycache__/ | ||
*.pyc | ||
*.pyo | ||
*.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Natthasath Saksupanara | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 🎉 Template Python FastAPI Exceptions | ||
|
||
Exceptions are events that occur during program execution that disrupt the normal flow of code. They can be caught and handled, allowing for more robust and error-resistant programs. | ||
|
||
![version](https://img.shields.io/badge/version-1.0-blue) | ||
![rating](https://img.shields.io/badge/rating-★★★★★-yellow) | ||
![uptime](https://img.shields.io/badge/uptime-100%25-brightgreen) | ||
|
||
### 🏆 Run | ||
|
||
- [http://localhost:8000/docs](http://localhost:8000/docs) | ||
- [http://localhost:8000/subapi/docs](http://localhost:8000/subapi/docs) | ||
|
||
```shell | ||
docker-compose up -d | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from app.routers import template, client, server | ||
from app.tag import SubTags, Tags | ||
|
||
app = FastAPI( | ||
title="FastAPI", | ||
description="Web API helps you do awesome stuff. 🚀", | ||
version="0.0.1", | ||
terms_of_service="http://example.com/terms/", | ||
contact={ | ||
"name": "Information and Digital Technology Center (IDT)", | ||
"url": "https://codeinsane.wordpress.com/", | ||
"email": "natthasath.sak@gmail.com", | ||
}, | ||
license_info={ | ||
"name": "Apache 2.0", | ||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html", | ||
}, | ||
openapi_url="/api/v1/openapi.json", | ||
docs_url="/docs", | ||
openapi_tags=Tags(), | ||
swagger_ui_parameters={"defaultModelsExpandDepth": -1} | ||
) | ||
|
||
origins = ["*"] | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router(client.router) | ||
app.include_router(server.router) | ||
# | ||
# | ||
|
||
subapi = FastAPI(openapi_tags=SubTags(), swagger_ui_parameters={"defaultModelsExpandDepth": -1}) | ||
|
||
subapi.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
subapi.include_router(template.router) | ||
# | ||
# | ||
# | ||
|
||
app.mount("/subapi", subapi) |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from typing import Any | ||
from fastapi.exception_handlers import HTTPException | ||
|
||
class BadRequestException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=400, detail=detail) | ||
|
||
class UnauthorizedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=401, detail=detail) | ||
|
||
class PaymentRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=402, detail=detail) | ||
|
||
class ForbiddenException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=403, detail=detail) | ||
|
||
class NotFoundException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=404, detail=detail) | ||
|
||
class MethodNotAllowedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=405, detail=detail) | ||
|
||
class NotAcceptableException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=406, detail=detail) | ||
|
||
class ProxyAuthenticationRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=407, detail=detail) | ||
|
||
class RequestTimeoutException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=408, detail=detail) | ||
|
||
class ConflictException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=409, detail=detail) | ||
|
||
class GoneException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=410, detail=detail) | ||
|
||
class LengthRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=411, detail=detail) | ||
|
||
class PreconditionFailedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=412, detail=detail) | ||
|
||
class PayloadTooLargeException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=413, detail=detail) | ||
|
||
class URITooLongException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=414, detail=detail) | ||
|
||
class UnsupportedMediaTypeException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=415, detail=detail) | ||
|
||
class RangeNotSatisfiableException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=416, detail=detail) | ||
|
||
class ExpectationFailedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=417, detail=detail) | ||
|
||
class ImATeapotException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=418, detail=detail) | ||
|
||
class MisdirectedRequestException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=421, detail=detail) | ||
|
||
class UnprocessableEntityException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=422, detail=detail) | ||
|
||
class LockedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=423, detail=detail) | ||
|
||
class FailedDependencyException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=424, detail=detail) | ||
|
||
class TooEarlyException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=425, detail=detail) | ||
|
||
class UpgradeRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=426, detail=detail) | ||
|
||
class PreconditionRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=428, detail=detail) | ||
|
||
class TooManyRequestsException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=429, detail=detail) | ||
|
||
class RequestHeaderFieldsTooLargeException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=431, detail=detail) | ||
|
||
class NoResponseException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=444, detail=detail) | ||
|
||
class UnavailableForLegalReasonsException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=451, detail=detail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Any | ||
from fastapi.exception_handlers import HTTPException | ||
|
||
class InternalServerErrorException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=500, detail=detail) | ||
|
||
class NotImplementedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=501, detail=detail) | ||
|
||
class BadGatewayException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=502, detail=detail) | ||
|
||
class ServiceUnavailableException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=503, detail=detail) | ||
|
||
class GatewayTimeoutException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=504, detail=detail) | ||
|
||
class HTTPVersionNotSupportedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=505, detail=detail) | ||
|
||
class VariantAlsoNegotiatesException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=506, detail=detail) | ||
|
||
class InsufficientStorageException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=507, detail=detail) | ||
|
||
class LoopDetectedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=508, detail=detail) | ||
|
||
class NotExtendedException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=510, detail=detail) | ||
|
||
class NetworkAuthenticationRequiredException(HTTPException): | ||
def __init__(self, detail: Any = None) -> None: | ||
super().__init__(status_code=511, detail=detail) |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from fastapi import Form | ||
from pydantic import BaseModel, Field, EmailStr, SecretStr | ||
from typing import List, Union | ||
import inspect | ||
|
||
def form_body(cls): | ||
cls.__signature__ = cls.__signature__.replace( | ||
parameters=[ | ||
arg.replace(default=Form(default = arg.default) if arg.default is not inspect._empty else Form(...)) | ||
for arg in cls.__signature__.parameters.values() | ||
] | ||
) | ||
return cls | ||
|
||
@form_body | ||
class TemplateSchema(BaseModel): | ||
id: int = Field(default=None) | ||
|
||
class Config: | ||
schema_extra = { | ||
"example": { | ||
"id": "Incremental Number" | ||
} | ||
} |
Oops, something went wrong.