
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
@rest-hooks/rest
Advanced tools
Extensible CRUD patterns for REST APIs.
import { Entity, createResource } from '@rest-hooks/rest';
class Article extends Entity {
id: number | undefined = undefined;
title = '';
body = '';
pk() {
return this.id;
}
}
const ArticleResource = createResource({
path: '/articles/:id',
schema: Article,
});
Entity defines a data model. createResource creates a collection of six RestEndpoints
RestEndpoints are functions (and more) that return a Promise. Both call parameters and return value are automatically inferred from the options used to construct them.
path is a templating language using path-to-regex compile.
const article = useSuspense(ArticleResource.get, { id: 5 });
const articles = useSuspense(ArticleResource.getList);
const [article, setArticle] = useState();
useEffect(() => {
setArticle(await ArticleResource.get({ id: 5 }));
}, []);
const ctrl = useController();
const updateArticle = data => ctrl.fetch(ArticleResource.update, { id }, data);
const partialUpdateArticle = data =>
ctrl.fetch(ArticleResource.partialUpdate, { id }, data);
const createArticle = data => ctrl.fetch(ArticleResource.create, data);
const deleteArticle = data => ctrl.fetch(ArticleResource.delete, { id });
const article = await ArticleResource.get({ id: 5 });
const articles = await ArticleResource.getList();
const sortedArticles = new Query(
new schema.All(Article),
(entries, { asc } = { asc: false }) => {
const sorted = [...entries].sort((a, b) => a.title.localeCompare(b.title));
if (asc) return sorted;
return sorted.reverse();
},
);
const articlesUnsorted = useCache(sortedArticles);
const articlesAscending = useCache(sortedArticles, { asc: true });
const articlesDescending = useCache(sortedArticles, { asc: false });
TypeScript is optional, but will only work with 4.0 or above. 4.1 is needed for stronger types as it supports inferring argument types from the path templates.
Version 5.x can be used for older TypeScript versions.
FAQs
Endpoints for REST APIs
The npm package @rest-hooks/rest receives a total of 1,285 weekly downloads. As such, @rest-hooks/rest popularity was classified as popular.
We found that @rest-hooks/rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.