Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
literium-request
Advanced tools
This project is part of Literium WEB-framework but can be used standalone.
The Literium applications used Fetch API some time ago. The fetch adds overhead related to promises, but Literium uses own less complex and lightweight alternative to promises which is called futures. Unlike promises which has two final states (resolved and rejected) the Literium futures has single final (resolved) which can hold either value or error.
The API have single function, named request
, which gets request data and returns future of result with response data as a value and string as an error.
function request(req: GenericRequest): Future<Result<GenericResponse, string>>;
The simple way to run request shown in the example below:
import { is_ok, un_ok } from 'literium-base';
import { request, Method, Status, DataType } from 'literium-request';
request({
method: Method.Get,
url: '/some/api/path',
headers: { accept: 'application/json' }
response: DataType.String,
})(res => {
if (is_ok(res)) {
const { status, message, body } = un_ok(res);
if (status == 200 &&
message == 'OK') {
const data = JSON.parse(body);
// do something with data
}
})
There is some correct use-cases for requests. This package provides corresponding typing rules to check correctness of request construction by TypeScript compiler.
For example, you can do POST
or PUT
requests with body but you cannot do GET
or DELETE
requests with body.
The simple requests haven't body.
interface RequestWithoutBody<TMethod extends Method> {
method: TMethod;
url: string;
headers?: Headers;
timeout?: number;
progress?: Send<Progress>;
}
The methods of requests without body is: GET
, HEAD
, and DELETE
.
interface RequestWithBody<TMethod extends Method> extends RequestWithoutBody<TMethod> {
body: GenericBody;
}
The methods of requests with body is: POST
, PUT
, and PATCH
.
To set preferred type of response body use response
field of request.
interface WithResponseBody<TData extends DataType> {
response: TData;
}
You must set response type when you need body contents of response, else you won't be able to read it at all.
The responses which never have body is: HEAD
, DELETE
and OPTIONS
.
Currently you can set request headers and get response headers as dictionary with string keys and values:
type Headers = Record<string, string>;
The types headers system, like that Rust's Hyper provides, is not implemented because it adds extra complexity level.
The available/allowed header names related to user-agent restrictions.
You can send and receive text and binary data in body:
const enum DataType {
String,
Binary,
}
type GenericBody = string | ArrayBuffer;
To receive progress events you may set progress
field of request.
The progress event looks like below:
interface Progress {
left: number; // loaded bytes
size: number; // total bytes
down: boolean; // true when downloading, false when uploading
}
FAQs
Request module for Literium web-framework.
The npm package literium-request receives a total of 4 weekly downloads. As such, literium-request popularity was classified as not popular.
We found that literium-request demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.