Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@exceptionless/fetchclient
Advanced tools
A simple fetch client with middleware support for Deno and the browser.
FetchClient is a library that makes it easier to use the fetch API for JSON APIs. It provides the following features:
npm install --save @exceptionless/fetchclient
Get a typed JSON response:
import { FetchClient } from '@exceptionless/fetchclient';
type Products = {
products: Array<{ id: number; name: string }>;
};
const client = new FetchClient();
const response = await client.getJSON<Products>(
`https://dummyjson.com/products/search?q=iphone&limit=10`,
);
const products = response.data;
Get a typed JSON response using a function:
import { useFetchClient } from '@exceptionless/fetchclient';
type Products = {
products: Array<{ id: number; name: string }>;
};
const response = await useFetchClient().getJSON<Products>(
`https://dummyjson.com/products/search?q=iphone&limit=10`,
);
const products = response.data;
Use a model validator:
import { FetchClient, setModelValidator } from '@exceptionless/fetchclient';
setModelValidator(async (data: object | null) => {
// use zod or any other validator
const problem = new ProblemDetails();
const d = data as { password: string };
if (d?.password?.length < 6) {
problem.errors.password = [
"Password must be longer than or equal to 6 characters.",
];
}
return problem;
});
const client = new FetchClient();
const data = {
email: "test@test",
password: "test",
};
const response = await client.postJSON(
"https://jsonplaceholder.typicode.com/todos/1",
data,
);
if (!response.ok) {
// check response problem
console.log(response.problem.detail);
}
Use caching:
import { FetchClient } from '@exceptionless/fetchclient';
type Todo = { userId: number; id: number; title: string; completed: boolean };
const client = new FetchClient();
const response = await client.getJSON<Todo>(
`https://jsonplaceholder.typicode.com/todos/1`,
{
cacheKey: ["todos", "1"],
cacheDuration: 1000 * 60, // expires in 1 minute
}
);
// invalidate programmatically
client.cache.delete(["todos", "1"]);
Use middleware:
import { FetchClient, useMiddleware } from '@exceptionless/fetchclient';
type Products = {
products: Array<{ id: number; name: string }>;
};
useMiddleware(async (ctx, next) => {
console.log('starting request')
await next();
console.log('completed request')
});
const client = new FetchClient();
const response = await client.getJSON<Products>(
`https://dummyjson.com/products/search?q=iphone&limit=10`,
);
Also, take a look at the tests:
Run tests:
deno test --allow-net
Lint code:
deno lint
Format code:
deno fmt
Type check code:
deno check scripts/*.ts *.ts src/*.ts
MIT © Exceptionless
FAQs
A simple fetch client with middleware support for Deno and the browser.
The npm package @exceptionless/fetchclient receives a total of 338 weekly downloads. As such, @exceptionless/fetchclient popularity was classified as not popular.
We found that @exceptionless/fetchclient demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.