The HTTP system provides a functional implementation for making HTTP requests. It follows the FlexNet JSX Framework's core principles:
- Functional programming
- Zero external dependencies
- Immutable state management
- Effect isolation
Request = Method -> URL -> Headers -> Body -> Timeout -> Retry -> Cache -> Either Error RequestResponse = Data -> Status -> Headers -> Either Error ResponseCache = Entries -> MaxAge -> MaxSize -> Either Error CacheInterceptor = (Request -> Either Error Request) -> (Response -> Either Error Response) -> (Error -> Either Error Error) -> Either Error Interceptorconst client = createHTTPClient(baseURL)(options);// GET request
client.get(url)(headers)(timeout)(retry)(cache);
// POST request
client.post(url)(data)(headers)(timeout)(retry)(cache);
// PUT request
client.put(url)(data)(headers)(timeout)(retry)(cache);
// DELETE request
client.delete(url)(headers)(timeout)(retry)(cache);// Add request interceptor
client.addRequestInterceptor(request =>
Either.Right({ ...request, headers: { ...request.headers, 'X-Custom': 'value' } })
);
// Add response interceptor
client.addResponseInterceptor(response =>
Either.Right({ ...response, data: transformData(response.data) })
);
// Add error interceptor
client.addErrorInterceptor(error =>
error.status === 401 ? refreshToken().chain(() => retry(error.request)) : Either.Left(error)
);// Get current cache state
const cache = client.getCache();
// Clear cache
client.clearCache();All types include strict verification:
- Request verification ensures valid method, URL, headers, timeout, retry config
- Response verification ensures valid status code, headers, data format
- Cache verification ensures valid entries, max age, max size
- Interceptor verification ensures valid function types
All operations return Either type for proper error handling:
client.get('/api/data')(headers)(timeout)(retry)(cache)
.map(response => processData(response.data))
.mapLeft(error => logError(error));All side effects (network requests, cache operations) are properly isolated in the effect system using functional composition.