ketting
Version:
Opinionated HATEOAS / Rest client.
23 lines (18 loc) • 592 B
text/typescript
import { BaseHeadState } from './base-state.js';
import { parseLink } from '../http/util.js';
import Client from '../client.js';
/**
* Turns the response to a HTTP Head request into a HeadState object.
*
* HeadState is a bit different from normal State objects, because it's
* missing a bunch of information.
*/
export const factory = async (client: Client, uri: string, response: Response): Promise<BaseHeadState> => {
const links = parseLink(uri, response.headers.get('Link'));
return new BaseHeadState({
client,
uri,
headers: response.headers,
links,
});
};