-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
64076d7
commit 8468972
Showing
3 changed files
with
10 additions
and
30 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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
from example.protocol import BookProtocol, Book | ||
from pydantic_client import PydanticClient, ClientConfig | ||
from pydantic_client.clients import RequestsClient | ||
from example.protocol import BookProtocol, Book, AuthorProtocol, Author | ||
from pydantic_client import pydantic_client_factory, ClientConfig | ||
|
||
if __name__ == "__main__": | ||
cfg = ClientConfig( | ||
client_type="requests", | ||
base_url="https://example.com/api" | ||
) | ||
client = PydanticClient(cfg) \ | ||
.bind_client(RequestsClient) \ | ||
.bind_protocol(BookProtocol) \ | ||
.build() | ||
|
||
pydantic_client_factory.register(cfg)(BookProtocol) | ||
pydantic_client_factory.register(cfg)(AuthorProtocol) | ||
|
||
client = pydantic_client_factory.get_client(BookProtocol) | ||
book: Book = client.get_book(1, "name") | ||
|
||
author_client = pydantic_client_factory.get_client(AuthorProtocol) | ||
author: Author = author_client.get_author() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.