hx
Client
Explicit open / close... (recommended)
>>> with hx.Client() as c:
>>> ...
Simple usage...
>>> c = hx.Client()
>>> c.close()
Requests...
>>> c = hx.Client()
>>> r = c.get('https://www.example.com/')
>>> r
<Response [200 OK]>
>>> c = hx.Client()
>>> u = hx.URL('https://www.example.com/', params={'search': '...'})
>>> r = c.get(u)
>>> r
<Response [200 OK]>
>>> f = hx.Form({'email': '...', 'message': '...'})
>>> r = c.post('https://www.example.com/', content=f)
>>> r
<Response [200 OK]>
>>> j = hx.JSON({'title': ..., 'rating': ...})
>>> r = c.put('https://www.example.com/', content=j)
>>> r
<Response [200 OK]>
>>> j = hx.JSON({'title': ..., 'rating': ...})
>>> r = c.patch('https://www.example.com/', content=j)
>>> r
<Response [200 OK]>
>>> c = hx.Client()
>>> r = c.delete('https://www.example.com/')
>>> r
<Response [200 OK]>
>>> c = hx.Client()
>>> r = c.head('https://www.example.com/')
>>> r
<Response [200 OK]>
Server
Explicit open / close... (recommended)
>>> with hx.Server(app) as s:
... # Serve until Ctrl-C, non-blocking
... print(s.url)
Simple usage...
>>> s = hx.Server(app)
>>> s.serve() # Serve until Ctrl-C
Address...
>>> # Serve locally, use an unassigned port.
>>> s = hx.Server(app, addr='127.0.0.1')
>>> # Serve locally, use a fixed port.
>>> s = hx.Server(app, addr='127.0.0.1:8000')
>>> # Serve globally, use a fixed port.
>>> s = hx.Server(app, addr='0.0.0.0:8000')
>>> # Serve globally, enforcing domain name and SSL.
>>> s = hx.Server(app, addr='https://www.domainname.com')
Request
>>> r = hx.Request(method, url, headers=..., content=...)
Attributes...
>>> r = hx.Request('GET', 'https://www.example.com')
>>> r.method
>>> r.url
>>> r.headers
>>> r.content
Response
>>> r = hx.Response(status_code, headers=..., content=...)
Attributes...
>>> r = hx.Response(200, content=hx.JSON({'message': 'hello, world'}))
>>> r.status_code
>>> r.headers
>>> r.content
Method
>>> m = hx.Method('GET')
>>> m == 'GET'
True
>>> str(m)
'GET'
StatusCode
>>> s = hx.StatusCode(200)
>>> s.value, s.reason
(200, 'OK')
>>> s == 200
True
Status classes...
>>> s = hx.StatusCode(200)
>>> s.is_1xx_informational()
False
>>> s.is_2xx_success()
True
>>> s.is_3xx_redirect()
False
>>> s.is_4xx_client_error()
False
>>> s.is_5xx_server_error()
False
Headers
>>> h = hx.Headers({...})
>>> h['Content-Type']
...
>>> h.get('content-type')
...
Multi-dict...
>>> h.get_all('set-cookie')
>>> h.multi_items()
Updates...
>>> h = h.copy_set(...)
>>> h = h.copy_append('set-cookie', 'session_id=...')
>>> h = h.copy_remove(...)
>>> h = h.copy_update(...)
URL
>>> u = hx.URL('...')
>>> u == '...'
True
Query parameters...
>>> u = hx.URL('...', params={'search': ...})
>>> u.params
<QueryParams ...>
Components...
>>> u.scheme
>>> u.host
>>> u.port
>>> u.path
>>> u.query
>>> u.netloc # 'example.com:8080' (HTTP request Host header)
>>> u.target # '/path?query' (HTTP request target)
Instantiate from components...
>>> u = hx.URL(scheme='https', host='www.example.com', path='/')
Updates...
>>> u = u.copy_with(scheme='https')
Joins...
>>> u = hx.URL('https://www.example.com/location')
>>> u = u.join('/redirect')
QueryParams
>>> q = hx.QueryParams("...")
>>> q['...']
>>> q.get('...')
Multi-dict...
>>> q.get_all()
...
>>> q.multi_items()
...
Updates...
>>> q = q.copy_set('search', '...')
>>> q = q.copy_append('color', 'red')
>>> q = q.copy_remove('ordering')
>>> q = q.copy_update({...})
Content
Content types for requests...
>>> j = hx.JSON(...)
>>> f = hx.Form(...)
>>> m = hx.MultiPart(...)
Content types for responses...
>>> h = hx.HTML('<html><body>¡Hola, mundo!</body></html>')
>>> t = hx.Text('hello, world')
>>> j = hx.JSON({'content': ...})
>>> f = hx.File('image.png')
— 💖 —