Skip to content

Instantly share code, notes, and snippets.

@shaurya-blip
Last active February 5, 2021 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaurya-blip/19ba02106d5631c1fc898dff9da18c3a to your computer and use it in GitHub Desktop.
Save shaurya-blip/19ba02106d5631c1fc898dff9da18c3a to your computer and use it in GitHub Desktop.
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