
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.