HTTP
Provides HTTP protocol functionality.
http.star
load("http@v0", "http")
Client
The Client can be used in two ways:
- Perform HTTP verb directly; e.g
get,post,delete, etc. - Perform
dowith a providedRequest
Constructor
client.star
# basic
http.client()
# with timeout
load("time@v0", "time")
http.client(timeout = time.SECOND * 30)
# with error callback
load("retry@v0", "retry")
http.client(
on_error = lambda error_message: retry.FAIL if error_message == "test" else retry.RETRY
)
# with retry
load("retry@v0", "retry")
load("time@v0", "time")
http.client(retry_strategy = retry.constant(time.SECOND))
Arguments
| Name | Type |
|---|---|
| timeout | time.Duration |
| on_error | function |
| retry_strategy | retry.Strategy |
Attributes
| Name | Arguments | Returns |
|---|---|---|
| get | url: stringheaders: dict<string, string> | http.Response |
| post | url: stringheaders: dict<string, string>body: string | http.Response |
| post_form | url: stringheaders: dict<string, string>body: dict<string, any> | http.Response |
| put | url: stringheaders: dict<string, string>body: string | http.Response |
| delete | url: stringheaders: dict<string, string> | http.Response |
| trace | url: stringheaders: dict<string, string> | http.Response |
| options | url: stringheaders: dict<string, string> | http.Response |
| head | url: stringheaders: dict<string, string> | http.Response |
| patch | url: stringheaders: dict<string, string> | http.Response |
| do | http.Request | http.Response |
Examples
client.star
client = http.client()
# get
client.get(
url = "https://docs.bckground.com",
headers = {"Accept":"text/html"}
)
# post
client.post(
url = "https://docs.bckground.com",
headers = {"Accept":"application/json"}
)
# post form
client.post_form(
url = "https://docs.bckground.com",
headers = {
"Accept":"application/json",
"Content-Type":"application/x-www-form-urlencoded"
},
form = {"foo" : "bar" }
)
# put
client.put(
url = "https://docs.bckground.com",
headers = {"Content-Type":"text/html"},
body = "<html/>"
)
# delete
client.delete(url = "https://docs.bckground.com")
# trace
client.trace(url = "https://docs.bckground.com")
# options
client.options(url = "https://docs.bckground.com")
# head
client.head(url = "https://docs.bckground.com")
# patch
client.patch(url = "https://docs.bckground.com")
# do
client.do(
http.request(url = "https://docs.bckground.com", method = http.GET)
)
Request
Constructor
request.star
http.request(
url = "https://docs.bckground.com",
method = http.GET,
headers = { "Accept": "text/html" }
)
Arguments
| Name | Type |
|---|---|
| url | string |
| method | http.Method |
| headers | dict<string, string> |
Attributes
| Name | Arguments | Returns |
|---|---|---|
| method | string | |
| url | string | |
| proto_major | int | |
| proto_minor | int | |
| header | dict<string, string> | |
| body | string | |
| content_length | int64 | |
| transfer_encoding | list<string> | |
| host | string | |
| remote_addr | string | |
| request_uri | string | |
| response | http.Response | |
| cookies | list<http.Cookie> | |
| referer | string | |
| user_agent | string | |
| add_cookie | http.Cookie | none |
Response
Attributes
| Name | Returns |
|---|---|
| status | string |
| status_code | http.StatusCode |
| proto | string |
| proto_major | int |
| proto_minor | int |
| header | dict<string, string> |
| body | string or none |
| content_length | int64 |
| transfer_encoding | list<string> |
| uncompressed | boolean |
| request | http.Request |
| cookies | list<http.Cookie> |
| location | string |
Cookie
Constructor
client.star
http.cookie(name = "custom.analytics", value = "foo=bar")
Arguments
| Name | Type |
|---|---|
| name | string |
| value | string |
Attributes
| Name | Arguments | Returns |
|---|---|---|
| name | string | |
| value | string | |
| quoted | boolean | |
| path | string | |
| domain | string | |
| expires | time.Time | |
| raw_expires | string | |
| max_age | int | |
| secure | boolean | |
| http_only | boolean | |
| same_site | int | |
| partitioned | boolean | |
| raw | string | |
| unparsed | list<string> |
Constants
HTTP Methods
| Name | Returns |
|---|---|
GET | string |
HEAD | string |
POST | string |
PUT | string |
PATCH | string |
DELETE | string |
CONNECT | string |
OPTIONS | string |
TRACE | string |
Statuses
| Name | Returns |
|---|---|
STATUS_CONTINUE | string |
STATUS_SWITCHING_PROTOCOLS | string |
STATUS_PROCESSING | string |
STATUS_EARLY_HINTS | string |
STATUS_OK | string |
STATUS_CREATED | string |
STATUS_ACCEPTED | string |
STATUS_NON_AUTHORITATIVE_INFO | string |
STATUS_NO_CONTENT | string |
STATUS_RESET_CONTENT | string |
STATUS_PARTIAL_CONTENT | string |
STATUS_MULTI_STATUS | string |
STATUS_ALREADY_REPORTED | string |
STATUS_IM_USED | string |
STATUS_MULTIPLE_CHOICES | string |
STATUS_MOVED_PERMANENTLY | string |
STATUS_FOUND | string |
STATUS_SEE_OTHER | string |
STATUS_NOT_MODIFIED | string |
STATUS_USE_PROXY | string |
STATUS_TEMPORARY_REDIRECT | string |
STATUS_PERMANENT_REDIRECT | string |
STATUS_BAD_REQUEST | string |
STATUS_UNAUTHORIZED | string |
STATUS_PAYMENT_REQUIRED | string |
STATUS_FORBIDDEN | string |
STATUS_NOT_FOUND | string |
STATUS_METHOD_NOT_ALLOWED | string |
STATUS_NOT_ACCEPTABLE | string |
STATUS_PROXY_AUTH_REQUIRED | string |
STATUS_REQUEST_TIMEOUT | string |
STATUS_CONFLICT | string |
STATUS_GONE | string |
STATUS_LENGTH_REQUIRED | string |
STATUS_PRECONDITION_FAILED | string |
STATUS_REQUEST_ENTITY_TOO_LARGE | string |
STATUS_REQUEST_URI_TOO_LONG | string |
STATUS_UNSUPPORTED_MEDIA_TYPE | string |
STATUS_REQUESTED_RANGE_NOT_SATISFIABLE | string |
STATUS_EXPECTATION_FAILED | string |
STATUS_TEAPOT | string |
STATUS_MISDIRECTED_REQUEST | string |
STATUS_UNPROCESSABLE_ENTITY | string |
STATUS_LOCKED | string |
STATUS_FAILED_DEPENDENCY | string |
STATUS_TOO_EARLY | string |
STATUS_UPGRADE_REQUIRED | string |
STATUS_PRECONDITION_REQUIRED | string |
STATUS_TOO_MANY_REQUESTS | string |
STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE | string |
STATUS_UNAVAILABLE_FOR_LEGAL_REASONS | string |
STATUS_INTERNAL_SERVER_ERROR | string |
STATUS_NOT_IMPLEMENTED | string |
STATUS_BAD_GATEWAY | string |
STATUS_SERVICE_UNAVAILABLE | string |
STATUS_GATEWAY_TIMEOUT | string |
STATUS_HTTP_VERSION_NOT_SUPPORTED | string |
STATUS_VARIANT_ALSO_NEGOTIATES | string |
STATUS_INSUFFICIENT_STORAGE | string |
STATUS_LOOP_DETECTED | string |
STATUS_NOT_EXTENDED | string |
STATUS_NETWORK_AUTHENTICATION_REQUIRED | string |