client module#
The HTTP plumbing both part sources need#
JSONClient is the only place in this package that speaks HTTP. Both the LCSC and the JLCPCB list APIs are unauthenticated JSON POST endpoints that report failure in the response body rather than the status line, so the two clients differ in their base URL, their paths and how the body wraps a result, and in nothing else.
Every failure, including a transport error, a failure code in the body and malformed JSON, is raised as ProviderUnavailable. That is what lets a design with a populated lockfile build on a box with no network: the chain reports itself unreachable and the lock answers instead.
- class JSONClient(base_url, timeout=20.0, attempts=2)[source]#
Bases:
ABCPOSTs JSON to one host and unwraps whatever envelope it answers with.
- Parameters:
- abstractmethod unwrap(path, payload)[source]#
The result object inside a decoded response body.
Raises ProviderUnavailable when the body says the request failed, which is where the two APIs’ envelopes differ: LCSC answers {“code”: 200, “result”: …} and JLCPCB {“code”: 200, “data”: …}, both reporting failure with a non-200 code and HTTP 200.
A ProviderUnavailable naming this client, for unwrap to raise.
- Return type:
- Parameters:
message (str)