Eve Networking
The layers
| Layer | What it does | In Eve |
|---|---|---|
| names and addresses | a host name becomes an address | a Url type and a resolver: planned |
| connection | TCP or QUIC, with TLS for secrecy | the module net: planned |
| protocol | the rules of a conversation: HTTP, EWP | see Protocols |
| data | the bytes become values: JSON, CSV, binary | the modules json, csv, txt: designed, level 5 (Files and ETL) |
| application | what the program does with the data | drivers, aspects, jobs |
Eve as a client
The first step is to call other systems: fetch a file, call a REST service, send a result. The calls wait for the network, and while a task waits it gives the turn away, so the tasks of one job can overlap many requests (see Multitasking), and aspects started in a parallel group can spread them on several cores (see Concurrency).
** version 0.4 (level 5): the HTTP client, the module http is in scope without an import
new answer := http.get!("https://api.example.com/orders", timeout: 10s,
headers: {"Accept": "application/json"});
answer.check(); ** raises HttpError for a status of 400 or more
for o in json.read!(:Order)(answer.body) do ** the body is a stream of bytes
print "{o.id}: {o.amount}";
done;
The client is part of level 5 (version 0.4); the server is level 6. http.get!, http.post!(url, body: ...) and http.request!(method, url, ...) give an HttpResponse with status, headers and body. A time-out raises TimeoutError, a refused connection ConnectionError (transient, a case for retry after). A header of type Secret goes on the wire but never to a log. Spec: spec/library/data-language.md#http-client.
Eve as a server
The same machine can answer requests: static files, JSON and HTML routes handled by aspects. The design is on the Server page.
Safety
- Capabilities: a project declares what it may reach (
net: "api.example.com"); an aspect declares what it needs; the machine refuses the rest. A browser machine reaches only its own origin; - Secrets: a token or password is a
Secret, never printed and never written to a log; it goes only to its sink; - Time-outs: every network call has a time-out (
$timeoutby default) and raises an error when it passes; - TLS: a connection to another machine is encrypted; a certificate that does not match is an error, not a warning.
Url; DNS; proxies; how a project file declares capabilities; the error classes of the network (NetError, TimeoutError).Url are still open (Q-028).Read next: Protocols