A TypeScript library for making HTTP requests with JSON.
- No dependencies
- 100% test coverage
- Supports Browser and Node.js
import{doRpc,NetworkError,ServerError,TimeoutError,UserError}from'@lyni/http-json-client'try{returnawaitdoRpc("POST","https://api.example.com/settings-save",{feature1: true,option2: "abc"},{timeout_ms: 10_000,headers: {'header1': 'val1'}},)}catch(e){if(einstanceofNetworkError){console.log("Error talking to server. Check your network connection.")}elseif(einstanceofTimeoutError){console.log("Error talking to server. Please try again later.")}elseif(einstanceofServerError){console.log(`Error talking to server: ${e.message} (${e.status??0})`)}elseif(einstanceofUserError){console.log(`Server returned ${JSON.stringify({user_error_message: e.message})} (${e.status})`)}}- 2025-08-06 v0.0.3 Fix release.sh.
- 2025-08-05 v0.0.2 Support uploading blobs. Add ServerError.is400() and is500().
- 2025-07-31 v0.0.1 Moved code from
lyni-nodeto this package.
./release.sh