Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@mvxiv/http-service
Advanced tools
useHttpService
(config, interceptors)
// http.service.js
import { useHttpService } from '@mvxiv/http-service';
import {
paramsSerializer,
requestSerializer,
responseSerializer
} from './lib/serializers';
import { right, left } from './lib/monades/either';
const config = {
baseURL: 'https://some-domain.com/api',
paramsSerializer,
transformRequest: [requestSerializer],
transformResponse: [responseSerializer],
};
// just example
const interceptors = {
request: [(config) => (config.headers['Accept'] = 'application/json'), undefined]
response: [
[res => right(res), error => left(error)]
],
};
export const {
httpService,
defineService,
setHeader,
setInterceptors
} = useHttpService(config, interceptors);
// user.service.js
export class UserService {
#httpService = null;
constructor(httpService) {
this.#httpService = httpService;
}
get http() {
return this.#httpService;
}
async getUser(params) {
return await this.http.get('/users/1', { params });
}
}
// products.js
import { httpService } from '../services/http.service.js'
httpService.get('/products', { params: { limit: 10, offset: 20 } });
createApiServiceContainer
(constructorsDict
, httpConfig
, httpInterceptors
)
httpConfig
and httpInterceptors
contracts equals to useHttpService
arguments.
constructorsDict
is dictionary of constructors (key, value pairs), for example:
// api.ioc.js
import { UserService } from '../services/user.service.js';
import { ProductService } from '../services/product.service.js';
const constructorsDict = {
UserService,
productService: ProductService
};
and use factory:
// api.ioc.js
// ...
import { createApiServiceContainer } from '@mvxiv/http-service';
//...
const config = {
baseURL: 'https//some-domain.com/api'
};
export const container = createApiServiceContainer(constructorsDict, config) // interceptors is optional param
BaseService
(httpService
)
Is class for inheritance and provide to your own classes context http methods and setHeader
method.
http methods provides: get, delete, head, options, post, put, patch
and axios special request
// transaction.service.js
import { BaseService } from '@mvxiv/http-service';
import { httpService } from '../services/http.service.js';
export class TransactionService extends BaseService {
constructor(httpService, some, other, args) {
super(httpService);
// ...
}
async getTransactions(params) {
return await this.get('/transactions', { params });
}
async createNewTransaction(payload) {
return await this.post('/transactions', payload);
}
}
FAQs
Http service for frontend build upon axios
The npm package @mvxiv/http-service receives a total of 0 weekly downloads. As such, @mvxiv/http-service popularity was classified as not popular.
We found that @mvxiv/http-service demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.