Last active
February 5, 2021 11:29
-
-
Save svalordev/19ba02106d5631c1fc898dff9da18c3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import requests | |
def create_book(title, author): | |
headers={ | |
'title':title, | |
'author':author | |
} | |
response = requests.post('http://127.0.0.1:8000/books/', headers) | |
print(f"New book {title} by {author} has been created,\n\n") | |
def get_all_books(): | |
response = requests.get('http://127.0.0.1:8000/books/') | |
return response.json() | |
create_book('Parallel worlds', 'Michio Kaku') | |
books = get_all_books() | |
for book in books: | |
print(f"Book {book['id']}:") | |
print(f" Title: {book['title']}") | |
print(f" By: {book['author']}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment