nx_api_sota_fetch.nx source
↩ module page · 56 lines · 4615 B
1// nx_api_sota_fetch.nx -- SOVEREIGN researcher: fetch the REAL state-of-the-art API-standard sources over our
2// own TLS (nx_https_fetch_follow + Mozilla CA) into knowledge/fetched/api_*.raw, so the API-SOTA census is
3// grounded in primary sources (OpenAPI/Swagger, RFC problem-details, MCP=agent-API, OWASP API-sec, maturity
4// models, JSON:API, AsyncAPI, gRPC) -- NOT memory. Operator: "benchmark vs swagger + others, EXCEED SOTA, be
5// API-only when working with Claude." license_tier: ORIGINAL depends: TLS stack + trust store
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_fetch_follow.nx"
10const K_MAGIC_8388608: i64 = 8388608
11const K_MAGIC_4194304: i64 = 4194304
12
13func af_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func af_n(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 }
15
16// fetch one url -> knowledge/fetched/<outfile>; print status + bytes (honest per-source result).
17func af_fetch(store: *TrustStore, url: *u8, outpath: *u8) -> i64 {
18 let cap: i64 = K_MAGIC_8388608; let buf: *u8 = sys_mmap(cap) // 8MB (RFCs/specs can be large)
19 let status: *i64 = sys_mmap(8) as *i64
20 let n: i64 = nx_https_fetch_follow(url, store, buf, cap, 6, status)
21 af_p(" " as *u8); af_p(outpath); af_p(" status=" as *u8); af_n(status[0]); af_p(" bytes=" as *u8); af_n(n)
22 if n > 0 {
23 let fd: i64 = sys_openat_wr(outpath, 0x1a4)
24 if fd >= 0 { sys_write(fd, buf, n); sys_close(fd); af_p(" SAVED\n" as *u8) } else { af_p(" (write-fail)\n" as *u8) }
25 } else { af_p(" FETCH-FAIL\n" as *u8) }
26 return n
27}
28
29func main() -> i64 {
30 af_p("NX-API-SOTA-FETCH (primary sources over sovereign TLS)\n" as *u8)
31 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
32 if r <= 0 { af_p("CA load FAILED\n" as *u8); sys_exit(1); return 1 }
33 let store: *TrustStore = r as *TrustStore
34 // OpenAPI 3.1 (== Swagger spec) -- the machine-readable-API benchmark
35 af_fetch(store, "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/versions/3.1.0.md" as *u8, "knowledge/fetched/api_openapi31.raw" as *u8)
36 // RFC 9457 Problem Details for HTTP APIs (the SOTA machine-readable error standard; obsoletes 7807)
37 af_fetch(store, "https://www.rfc-editor.org/rfc/rfc9457.txt" as *u8, "knowledge/fetched/api_rfc9457_problemjson.raw" as *u8)
38 // RFC 9110 HTTP Semantics (status codes / methods / conditional / range -- the substrate)
39 af_fetch(store, "https://www.rfc-editor.org/rfc/rfc9110.txt" as *u8, "knowledge/fetched/api_rfc9110_httpsem.raw" as *u8)
40 // MCP -- Model Context Protocol: the SOTA AGENT-facing API (tools/resources discoverable by an LLM) = "API-only with Claude"
41 af_fetch(store, "https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/README.md" as *u8, "knowledge/fetched/api_mcp.raw" as *u8)
42 // OWASP API Security Top 10 (2023) -- the security benchmark for APIs
43 af_fetch(store, "https://raw.githubusercontent.com/OWASP/API-Security/master/editions/2023/en/0x11-t10.md" as *u8, "knowledge/fetched/api_owasp_top10.raw" as *u8)
44 // Microsoft REST API Guidelines -- industry REST best-practice (versioning/pagination/errors/naming)
45 af_fetch(store, "https://raw.githubusercontent.com/microsoft/api-guidelines/vNext/Guidelines.md" as *u8, "knowledge/fetched/api_msft_rest.raw" as *u8)
46 // AsyncAPI -- event-driven API spec (streaming/webhooks; beyond request-response)
47 af_fetch(store, "https://raw.githubusercontent.com/asyncapi/spec/master/spec/asyncapi.md" as *u8, "knowledge/fetched/api_asyncapi.raw" as *u8)
48 // Richardson Maturity Model (REST levels 0-3 incl. HATEOAS/hypermedia)
49 af_fetch(store, "https://martinfowler.com/articles/richardsonMaturityModel.html" as *u8, "knowledge/fetched/api_richardson.raw" as *u8)
50 // JSON:API -- a mature response/error/pagination convention
51 af_fetch(store, "https://jsonapi.org/format/" as *u8, "knowledge/fetched/api_jsonapi.raw" as *u8)
52 // gRPC core concepts -- the high-performance contract-first RPC benchmark
53 af_fetch(store, "https://grpc.io/docs/what-is-grpc/core-concepts/" as *u8, "knowledge/fetched/api_grpc.raw" as *u8)
54 af_p("NX-API-SOTA-FETCH done -> knowledge/fetched/api_*.raw\n" as *u8)
55 sys_exit(0); return 0
56}