@@ -26,13 +26,13 @@ Installing from PyPI_:
26
26
27
27
.. code-block :: bash
28
28
29
- pip3 install base-http-client
29
+ pip install base-http-client
30
30
31
31
Installing from github.com:
32
32
33
33
.. code-block :: bash
34
34
35
- pip3 install git+https://github.com/andy-takker/base_http_client
35
+ pip install git+https://github.com/andy-takker/base_http_client
36
36
37
37
The package contains several extras and you can install additional dependencies
38
38
if you specify them in this way.
@@ -45,18 +45,52 @@ For example, with msgspec_:
45
45
46
46
Complete table of extras below:
47
47
48
- +----------------------------------------------- +----------------------------------+
49
- | example | description |
50
- +=============================================== +==================================+
51
- | ``pip3 install "base-http-client[msgspec]" `` | For using msgspec _ structs |
52
- +----------------------------------------------- +----------------------------------+
53
- | ``pip3 install "base-http-client[orjson]" `` | For fast parsing json by orjson _ |
54
- +----------------------------------------------- +----------------------------------+
55
- | ``pip3 install "base-http-client[pydantic]" `` | For using pydantic _ models |
56
- +----------------------------------------------- +----------------------------------+
48
+ +----------------------------------------------+----------------------------------+
49
+ | example | description |
50
+ +==============================================+==================================+
51
+ | ``pip install "base-http-client[msgspec]" `` | For using msgspec _ structs |
52
+ +----------------------------------------------+----------------------------------+
53
+ | ``pip install "base-http-client[orjson]" `` | For fast parsing json by orjson _ |
54
+ +----------------------------------------------+----------------------------------+
55
+ | ``pip install "base-http-client[pydantic]" `` | For using pydantic _ models |
56
+ +----------------------------------------------+----------------------------------+
57
57
58
- Using
59
- ~~~~~
58
+ Quick start guide
59
+ -----------------
60
+
61
+ BaseHttpClient
62
+ ~~~~~~~~~~~~~~
63
+
64
+ Simple HTTP Client for `https://catfact.ninja `. See full example in `examples/base_http_client.py `_
65
+
66
+ .. code-block :: python
67
+
68
+ from base_http_client.client import (
69
+ DEFAULT_TIMEOUT ,
70
+ BaseHttpClient,
71
+ ResponseHandlersType,
72
+ )
73
+ from base_http_client.handlers.pydantic import parse_model
74
+ from base_http_client.timeout import TimeoutType
75
+
76
+
77
+ class CatfactClient (BaseHttpClient ):
78
+ RANDOM_CATFACT_HANDLERS : ResponseHandlersType = MappingProxyType(
79
+ {
80
+ HTTPStatus.OK : parse_model(CatfactSchema),
81
+ }
82
+ )
83
+
84
+ async def fetch_random_cat_fact (
85
+ self ,
86
+ timeout : TimeoutType = DEFAULT_TIMEOUT ,
87
+ ) -> CatfactSchema:
88
+ return await self ._make_req(
89
+ method = hdrs.METH_GET ,
90
+ url = self ._url / " fact" ,
91
+ handlers = self .RANDOM_CATFACT_HANDLERS ,
92
+ timeout = timeout,
93
+ )
60
94
61
95
62
96
65
99
.. _aiohttp : https://pypi.org/project/aiohttp/
66
100
.. _msgspec : https://github.com/jcrist/msgspec
67
101
.. _orjson : https://github.com/ijl/orjson
68
- .. _pydantic : https://github.com/pydantic/pydantic
102
+ .. _pydantic : https://github.com/pydantic/pydantic
103
+
104
+ .. _examples/base_http_client.py : https://github.com/andy-takker/base_http_client/blob/master/examples/base_http_client.py
0 commit comments