├── app.py ├── readme.md ├── .gitignore └── data.json /app.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Body 2 | import json 3 | 4 | app = FastAPI() 5 | 6 | @app.get('/api/hello') 7 | def hello_world(): 8 | ''' 9 | Endpoint para exibir a mensagem mais famosa da programaçao 10 | ''' 11 | return {'hello':'world'} 12 | 13 | @app.get('/api/sayhi/{nome}') 14 | def say_hi(nome:str): 15 | return {'Oi': nome} 16 | 17 | @app.get('/api/bandas') 18 | def exibir_bandas(): 19 | '''Endpoint para listar todas as bandas do "banco de dados"''' 20 | with open('data.json', 'r') as file: 21 | dados = json.load(file) 22 | return dados 23 | 24 | @app.post('/api/bandas') 25 | def adicionar_nova_banda(banda: dict = Body): 26 | with open('data.json', 'r') as file: 27 | dados = json.load(file) 28 | dados.append(banda) 29 | with open('data.json', 'w') as file: 30 | json.dump(dados, file) -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # FastAPI Bandas API 2 | 3 | Esta é uma API simples construída com o framework FastAPI para gerenciar informações sobre bandas. A API oferece operações básicas, como visualizar bandas existentes e adicionar novas bandas ao "banco de dados". 4 | 5 | ## Endpoints 6 | 7 | ### 1. Hello World 8 | 9 | - **Endpoint**: `/api/hello` 10 | - **Método**: GET 11 | - **Descrição**: Retorna a mensagem mais famosa da programação. 12 | - **Exemplo de Resposta**: 13 | ```json 14 | {"hello": "world"} 15 | ``` 16 | 17 | ### 2. Saudação por Nome 18 | 19 | - **Endpoint**: `/api/sayhi/{nome}` 20 | - **Método**: GET 21 | - **Descrição**: Retorna uma saudação personalizada com base no nome fornecido. 22 | - **Exemplo de Resposta**: 23 | ```json 24 | {"Oi": "nome"} 25 | ``` 26 | 27 | ### 3. Listar Bandas 28 | 29 | - **Endpoint**: `/api/bandas` 30 | - **Método**: GET 31 | - **Descrição**: Retorna a lista de todas as bandas no "banco de dados". 32 | - **Exemplo de Resposta**: 33 | ```json 34 | [{"banda": "Nome da Banda 1", "genero": "Gênero 1"}, {"banda": "Nome da Banda 2", "genero": "Gênero 2"}, ...] 35 | ``` 36 | 37 | ### 4. Adicionar Nova Banda 38 | 39 | - **Endpoint**: `/api/bandas` 40 | - **Método**: POST 41 | - **Descrição**: Adiciona uma nova banda ao "banco de dados". 42 | - **Parâmetros de Corpo (Body)**: Um objeto JSON representando os detalhes da nova banda. 43 | - **Exemplo de Requisição**: 44 | ```json 45 | {"banda": "Nova Banda", "genero": "Novo Gênero"} 46 | ``` 47 | - **Exemplo de Resposta**: 48 | ```json 49 | {"message": "Banda adicionada com sucesso!"} 50 | ``` 51 | 52 | ## Executando Localmente 53 | 54 | 1. Instale as dependências: 55 | ```bash 56 | pip install fastapi uvicorn 57 | ``` 58 | 59 | 2. Execute o aplicativo: 60 | ```bash 61 | uvicorn nome_do_arquivo:app --reload 62 | ``` 63 | Substitua `nome_do_arquivo` pelo nome do arquivo que contém o código da API. 64 | 65 | 3. Acesse a documentação interativa da API em `http://127.0.0.1:8000/docs` para explorar e testar os endpoints. 66 | 67 | Lembre-se de adaptar o código conforme necessário para atender aos requisitos específicos do seu projeto. 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/python 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=python 3 | 4 | ### Python ### 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | cover/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | .pybuilder/ 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | # For a library or package, you might want to ignore these files since the code is 91 | # intended to run in multiple environments; otherwise, check them in: 92 | # .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # poetry 102 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 103 | # This is especially recommended for binary packages to ensure reproducibility, and is more 104 | # commonly ignored for libraries. 105 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 106 | #poetry.lock 107 | 108 | # pdm 109 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 110 | #pdm.lock 111 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 112 | # in version control. 113 | # https://pdm.fming.dev/#use-with-ide 114 | .pdm.toml 115 | 116 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 117 | __pypackages__/ 118 | 119 | # Celery stuff 120 | celerybeat-schedule 121 | celerybeat.pid 122 | 123 | # SageMath parsed files 124 | *.sage.py 125 | 126 | # Environments 127 | .env 128 | .venv 129 | env/ 130 | venv/ 131 | ENV/ 132 | env.bak/ 133 | venv.bak/ 134 | 135 | # Spyder project settings 136 | .spyderproject 137 | .spyproject 138 | 139 | # Rope project settings 140 | .ropeproject 141 | 142 | # mkdocs documentation 143 | /site 144 | 145 | # mypy 146 | .mypy_cache/ 147 | .dmypy.json 148 | dmypy.json 149 | 150 | # Pyre type checker 151 | .pyre/ 152 | 153 | # pytype static type analyzer 154 | .pytype/ 155 | 156 | # Cython debug symbols 157 | cython_debug/ 158 | 159 | # PyCharm 160 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 161 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 162 | # and can be added to the global gitignore or merged into this file. For a more nuclear 163 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 164 | #.idea/ 165 | 166 | ### Python Patch ### 167 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration 168 | poetry.toml 169 | 170 | # ruff 171 | .ruff_cache/ 172 | 173 | # LSP config files 174 | pyrightconfig.json 175 | 176 | # End of https://www.toptal.com/developers/gitignore/api/python -------------------------------------------------------------------------------- /data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Rolling Stones", 4 | "members": [ 5 | "Mick Jagger", 6 | "Keith Richards", 7 | "Ronnie Wood", 8 | "Charlie Watts" 9 | ], 10 | "formation_year": 1962 11 | }, 12 | { 13 | "name": "Led Zeppelin", 14 | "members": [ 15 | "Robert Plant", 16 | "Jimmy Page", 17 | "John Paul Jones", 18 | "John Bonham" 19 | ], 20 | "formation_year": 1968 21 | }, 22 | { 23 | "name": "Queen", 24 | "members": [ 25 | "Freddie Mercury", 26 | "Brian May", 27 | "Roger Taylor", 28 | "John Deacon" 29 | ], 30 | "formation_year": 1970 31 | }, 32 | { 33 | "name": "Pink Floyd", 34 | "members": [ 35 | "Roger Waters", 36 | "David Gilmour", 37 | "Richard Wright", 38 | "Nick Mason" 39 | ], 40 | "formation_year": 1965 41 | }, 42 | { 43 | "name": "The Who", 44 | "members": [ 45 | "Roger Daltrey", 46 | "Pete Townshend", 47 | "John Entwistle", 48 | "Keith Moon" 49 | ], 50 | "formation_year": 1964 51 | }, 52 | { 53 | "name": "U2", 54 | "members": [ 55 | "Bono", 56 | "The Edge", 57 | "Adam Clayton", 58 | "Larry Mullen Jr." 59 | ], 60 | "formation_year": 1976 61 | }, 62 | { 63 | "name": "AC/DC", 64 | "members": [ 65 | "Angus Young", 66 | "Brian Johnson", 67 | "Cliff Williams", 68 | "Phil Rudd" 69 | ], 70 | "formation_year": 1973 71 | }, 72 | { 73 | "name": "Nirvana", 74 | "members": [ 75 | "Kurt Cobain", 76 | "Krist Novoselic", 77 | "Dave Grohl" 78 | ], 79 | "formation_year": 1987 80 | }, 81 | { 82 | "name": "The Doors", 83 | "members": [ 84 | "Jim Morrison", 85 | "Ray Manzarek", 86 | "Robbie Krieger", 87 | "John Densmore" 88 | ], 89 | "formation_year": 1965 90 | }, 91 | { 92 | "name": "Red Hot Chili Peppers", 93 | "members": [ 94 | "Anthony Kiedis", 95 | "Flea", 96 | "Chad Smith", 97 | "John Frusciante" 98 | ], 99 | "formation_year": 1983 100 | }, 101 | { 102 | "name": "The Rolling Stones", 103 | "members": [ 104 | "Mick Jagger", 105 | "Keith Richards", 106 | "Charlie Watts", 107 | "Ronnie Wood" 108 | ], 109 | "formation_year": 1962 110 | }, 111 | { 112 | "name": "Guns N' Roses", 113 | "members": [ 114 | "Axl Rose", 115 | "Slash", 116 | "Duff McKagan", 117 | "Izzy Stradlin" 118 | ], 119 | "formation_year": 1985 120 | }, 121 | { 122 | "name": "Metallica", 123 | "members": [ 124 | "James Hetfield", 125 | "Lars Ulrich", 126 | "Kirk Hammett", 127 | "Robert Trujillo" 128 | ], 129 | "formation_year": 1981 130 | }, 131 | { 132 | "name": "The Cure", 133 | "members": [ 134 | "Robert Smith", 135 | "Simon Gallup", 136 | "Roger O'Donnell", 137 | "Jason Cooper" 138 | ], 139 | "formation_year": 1976 140 | }, 141 | { 142 | "name": "Radiohead", 143 | "members": [ 144 | "Thom Yorke", 145 | "Jonny Greenwood", 146 | "Colin Greenwood", 147 | "Ed O'Brien" 148 | ], 149 | "formation_year": 1985 150 | }, 151 | { 152 | "name": "Pearl Jam", 153 | "members": [ 154 | "Eddie Vedder", 155 | "Stone Gossard", 156 | "Jeff Ament", 157 | "Mike McCready" 158 | ], 159 | "formation_year": 1990 160 | }, 161 | { 162 | "name": "Foo Fighters", 163 | "members": [ 164 | "Dave Grohl", 165 | "Nate Mendel", 166 | "Pat Smear", 167 | "Taylor Hawkins" 168 | ], 169 | "formation_year": 1994 170 | }, 171 | { 172 | "name": "R.E.M.", 173 | "members": [ 174 | "Michael Stipe", 175 | "Peter Buck", 176 | "Mike Mills", 177 | "Bill Berry" 178 | ], 179 | "formation_year": 1980 180 | }, 181 | { 182 | "name": "The Smiths", 183 | "members": [ 184 | "Morrissey", 185 | "Johnny Marr", 186 | "Andy Rourke", 187 | "Mike Joyce" 188 | ], 189 | "formation_year": 1982 190 | }, 191 | { 192 | "name": "Bon Jovi", 193 | "members": [ 194 | "Jon Bon Jovi", 195 | "Richie Sambora", 196 | "David Bryan", 197 | "Tico Torres" 198 | ], 199 | "formation_year": 1983 200 | }, 201 | { 202 | "name": "Ramones", 203 | "members": [ 204 | "Joey Ramone", 205 | "Johnny Ramone", 206 | "Dee Dee Ramone", 207 | "Tommy Ramone" 208 | ], 209 | "formation_year": 1974 210 | }, 211 | { 212 | "name": "Deep Purple", 213 | "members": [ 214 | "Ian Gillan", 215 | "Roger Glover", 216 | "Ian Paice", 217 | "Steve Morse" 218 | ], 219 | "formation_year": 1968 220 | }, 221 | { 222 | "name": "The Clash", 223 | "members": [ 224 | "Joe Strummer", 225 | "Mick Jones", 226 | "Paul Simonon", 227 | "Topper Headon" 228 | ], 229 | "formation_year": 1976 230 | }, 231 | { 232 | "name": "Def Leppard", 233 | "members": [ 234 | "Joe Elliott", 235 | "Phil Collen", 236 | "Rick Savage", 237 | "Rick Allen" 238 | ], 239 | "formation_year": 1977 240 | }, 241 | { 242 | "name": "Journey", 243 | "members": [ 244 | "Steve Perry", 245 | "Neal Schon", 246 | "Ross Valory", 247 | "Steve Smith" 248 | ], 249 | "formation_year": 1973 250 | }, 251 | { 252 | "name": "The Eagles", 253 | "members": [ 254 | "Don Henley", 255 | "Glenn Frey", 256 | "Joe Walsh", 257 | "Timothy B. Schmit" 258 | ], 259 | "formation_year": 1971 260 | }, 261 | { 262 | "name": "Imersao Dev 7", 263 | "members": [ 264 | "Paulo Silveira", 265 | "Rafa Ballerini", 266 | "Gui Lima", 267 | "Voc\u00ea" 268 | ], 269 | "formation_year": 2023 270 | }, 271 | { 272 | "name": "Nova banda", 273 | "members": [ 274 | "Python", 275 | "JavaScript", 276 | "JacaScript", 277 | "Numero 7" 278 | ], 279 | "formation_year": 1995 280 | } 281 | ] --------------------------------------------------------------------------------