Gathering detailed insights and metrics for @khara/spring-data-rest-json-hal-client
Gathering detailed insights and metrics for @khara/spring-data-rest-json-hal-client
Gathering detailed insights and metrics for @khara/spring-data-rest-json-hal-client
Gathering detailed insights and metrics for @khara/spring-data-rest-json-hal-client
npm install @khara/spring-data-rest-json-hal-client
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Preconfigured rest npm package that acts like JSON+HAL JS-Client for Spring Data REST backend.
1'use strict'; 2 3const rest = require('rest'); 4const mime = require('rest/interceptor/mime'); 5const errorCode = require('rest/interceptor/errorCode'); 6const baseRegistry = require('rest/mime/registry'); 7 8const registry = baseRegistry.child(); 9registry.register('application/hal+json', require('rest/mime/type/application/hal')); 10registry.register('application/schema+json', require('rest/mime/type/application/json')); 11registry.register('application/json', require('rest/mime/type/application/json')); 12registry.register('multipart/form-data', require('rest/mime/type/multipart/form-data')); 13registry.register('text/plain', require('rest/mime/type/text/plain')); 14registry.register('text/uri-list', require('./mime/type/text/uri-list')); 15 16const client = rest 17 .wrap(mime, {registry: registry}) 18 .wrap(errorCode); 19 20module.exports = client;
First, import the needed operation (get
, post
, put
, patch
, del
or client
for backwards compatibility or more complicated operations) into your Javascript file where you are going to use it:
1import {get} from '@khara/spring-data-rest-json-hal-client';
or
1import {post} from '@khara/spring-data-rest-json-hal-client';
or
1import {put} from '@khara/spring-data-rest-json-hal-client';
or
1import {patch} from '@khara/spring-data-rest-json-hal-client';
or
1import {del} from '@khara/spring-data-rest-json-hal-client';
or
1import {client} from '@khara/spring-data-rest-json-hal-client';
(client
is for backwards compatibility or for real complicated operations that are not covered in simple requests) or more than one
1import {get, post, del} from '@khara/spring-data-rest-json-hal-client';
Then use it in the same fragment as in the following examples:
1... 2get('/api/users/all').then(successfulResponse => console.log(successfulResponse), error => console.error(error)); 3get('/api/users/all', {'Content-Type': 'application/json'}).then(successfulResponse => console.log(successfulResponse), error => console.error(error)); 4... 5client(/* Your request type and its required paramenters */).then(/* What should be done after request gets responded */); 6...
path
is always required logically, but headers and entity are optional depending from your services.
1get('/some/path').then(successfulResponse => console.log(successfulResponse), error => console.error(error));
or with headers
1get('/some/path', {'Content-Type': 'application/json'}).then(successfulResponse => console.log(successfulResponse), error => console.error(error));
or backwards compatible
1client({method: 'GET', path: '/some/path'}) 2 .then(response => { console.log('Success:', response)}, response => { console.log('Error:', response)}); 3... 4client({method: 'GET', path: '/some/path', headers: {'Content-Type': 'application/json'}}) 5 .then(response => { console.log('Success:', response)}, response => { console.log('Error:', response)});
1post('/some/path', {firstName: 'Max', lastName: 'Mustermann'}, {'Content-Type': 'application/json'}) 2 .then( 3 successfulResponse => {console.log('Success:', successfulResponse)}, 4 errorResponse => { 5 if (errorResponse.status.code === 403) { 6 alert('ACCESS DENIED: You are not authorized to update!'); 7 } else if (errorResponse.status.code === 412) { 8 alert('DENIED: Your copy is stale!'); 9 } else { 10 console.log(errorResponse); 11 } 12 });
or backwards compatible
1client({method: 'POST', path: '/some/path', entity: {firstName: 'Max', lastName: 'Mustermann'}, headers: {'Content-Type': 'application/json'}}) 2 .then( 3 response => {console.log('Success:', response)}, 4 response => { 5 if (response.status.code === 403) { 6 alert('ACCESS DENIED: You are not authorized to update!'); 7 } else if (response.status.code === 412) { 8 alert('DENIED: Your copy is stale!'); 9 } else { 10 console.log(response); 11 } 12 });
1put('/some/path', {firstName: 'Max', lastName: 'Mustermann'}, {'Content-Type': 'application/json'}) 2 .then( 3 successfulResponse => {console.log('Success:', successfulResponse)}, 4 errorResponse => { 5 if (errorResponse.status.code === 403) { 6 alert('ACCESS DENIED: You are not authorized to update!'); 7 } else if (errorResponse.status.code === 412) { 8 alert('DENIED: Your copy is stale!'); 9 } else { 10 console.log(errorResponse); 11 } 12 });
or backwards compatible
1client({method: 'PUT', path: '/some/path', entity: {firstName: 'Max', lastName: 'Mustermann'}, headers: {'Content-Type': 'application/json'}}) 2 .then( 3 response => {console.log('Success:', response)}, 4 response => { 5 if (response.status.code === 403) { 6 alert('ACCESS DENIED: You are not authorized to update!'); 7 } else if (response.status.code === 412) { 8 alert('DENIED: Your copy is stale!'); 9 } else { 10 console.log(response); 11 } 12 });
1del('/some/path', {'Content-Type': 'application/json'}) 2 .then(response => {console.log("Success:", response)}, response => 3 { 4 if (response.status.code === 403) { 5 alert('ACCESS DENIED: You are not authorized to delete!'); 6 } 7 else { 8 console.log(response); 9 } 10 });
or backwards compatible
1client({method: 'DELETE', path: '/some/path', headers: {'Content-Type': 'application/json'}}) 2 .then( 3 response => {console.log('Success:', response)}, 4 response => { 5 if (response.status.code === 403) { 6 alert('ACCESS DENIED: You are not authorized to delete!'); 7 } 8 else { 9 console.log(response); 10 } 11 });
No vulnerabilities found.
No security vulnerabilities found.