
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
semantic-link
Advanced tools
A utility library for manipulating a list of links that form a semantic interface to a resource.
A utility library for manipulating a list of links that form a semantic interface to a resource.
This library is able to work with atom-like representations (ATOM is an XML-based document format). We use this to describe collections which describes lists of related information collections (in atom known as "feeds"). Collections (feeds in atom) are composed of a number of items (in atom known as "entries") each with an extensible set of attached metadata or attributes.
The library has two aspects:
filter
,matches
,getUri
,getTitle
]get
,put
,post
,delete
, patch
, tryGet
]Very simple examples
import { getUri, matches, filter } from 'semantic-link';
import * as semanticLink from 'semantic-link';
const order = {
links: [
{ rel: "self", href: "http://example.com/order/1" }
]
title: "A first order"
}
getUri(order, /self/); // returns 'http://example.com/order/1'
matches(order, /self/); // returns true
filter(order, /self/); // returns order object
semanticLink.get(order, /self/); // HTTP GET on self link to return representation (via axios)
semanticLink.put(order, /self/, {title: 'Updated'}); // HTTP PUT on self link to send back data
Using yarn:
$ yarn add semantic-link
Note: this has a dependency on axios
//individually
import { getUri, getTitle, matches, filter, get, put, post, del, patch, tryGet } from 'semantic-link';
// as wildcard
import * as semanticLink from 'semantic-link';
The basic interface for matching is to look for link rels on the representation.
get(resource, 'self')
get(resource, /self/)
get(resource, /self|canonical/)
post(resource, ['submit', 'self'])
There are lots of ways to do this:
'self'
/self/
(anywhere)/^self$/
(must match-same as string match)/self|canonical/
(either)/edit-form/
['self', 'submit']
Note: you can have a list of regex too.
The basic interface for matching can also be specific to media type.
filter(resource, 'self')
matches(resource, 'edit-form', 'text/uri-list')
get(resource, 'self', 'application/json')
post(resource, 'submit', 'application/json-patch+json', data)
Note: When the media type is specified it must be found there is no fallback other types.
get
,put
,post
,delete
, patch
, tryGet
, link
)This is just a light wrapper around axios
and can have all the options of axios handed in.
// Promise based
get(resource, 'self')
.then(response => {
// type: AxiosResponse<LinkedRepresentation|CollectionRepresentation>
})
.then(err => {
// type: AxiosError
});
// or async/await (or with error handling try/catch)
const response = await get(resource, 'self');
There is also a specific param for a Cancellable
.
import { CancelToken } from 'axios';
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
get(resource, 'self', 'application/json', source.token)
source.cancel('Operation canceled by the user.');
Note: access to axios is through the link
interface (all the other methods call this) and the AxiosRequestConfig can
overridden on the options. Also note, it is likely that you'd be better to use the axios interceptors. There are a couple
of scenarios:
401
unauthorised should be implemented through interceptors, as well as setting of www-authenticate headersFAQs
A utility library for manipulating a list of links that form a semantic interface to a resource.
We found that semantic-link 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.