@mvxiv/http-service
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -25,17 +25,17 @@ export class BaseService { | ||
get(url, config) {} | ||
async get(url, config) {} | ||
delete(url, config) {} | ||
async delete(url, config) {} | ||
head(url, config) {} | ||
async head(url, config) {} | ||
options(url, config) {} | ||
async options(url, config) {} | ||
post(url, payload, config) {} | ||
async post(url, payload, config) {} | ||
put(url, payload, config) {} | ||
async put(url, payload, config) {} | ||
patch(url, payload, cofig) {} | ||
async patch(url, payload, config) {} | ||
request(config) {} | ||
async request(config) {} | ||
} |
@@ -19,11 +19,11 @@ import { useHttpService } from './http-service.js'; | ||
/** | ||
* @param { Object } serviceList | ||
* @param { Object } httpConfig - axios configuration | ||
* @param { Object } [httpInterceptors] - axios plugins (serializers, interceptors, etc.) | ||
* @param { object } constructorsDict | ||
* @param { object } httpConfig - axios configuration | ||
* @param { object } [httpInterceptors] - axios plugins (serializers, interceptors, etc.) | ||
* @return { * } apiServiceContainer | ||
*/ | ||
export const createApiServiceContainer = (serviceList, httpConfig, httpInterceptors) => { | ||
export const createApiServiceContainer = (constructorsDict, httpConfig, httpInterceptors) => { | ||
if (!httpConfig) throw new RequiredParamError('httpConfig', httpConfig); | ||
if (!serviceList) throw new RequiredParamError('serviceList', serviceList); | ||
if (!constructorsDict) throw new RequiredParamError('constructorsDict', constructorsDict); | ||
@@ -34,9 +34,6 @@ const { defineService, setHeader, setInterceptors } = useHttpService( | ||
); | ||
const constructors = new Set(serviceList); | ||
const container = serviceList.reduce((container, Service) => { | ||
const key = Service.name[0].toLowerCase() + Service.name.slice(1); | ||
const container = Object.entries(constructorsDict).reduce((container, [key, Service]) => { | ||
const instanceKey = key.charAt(0).toLowerCase() + key.slice(1); | ||
const service = defineService(Service)(); | ||
container[key] = autobindDecorator(service); | ||
constructors.add(constructor); | ||
container[instanceKey] = autobindDecorator(service); | ||
return container; | ||
@@ -43,0 +40,0 @@ }, {}); |
{ | ||
"name": "@mvxiv/http-service", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Http service for frontend build upon axios", | ||
@@ -10,8 +10,8 @@ "repository": { | ||
"type": "module", | ||
"main": "module.js", | ||
"types": "module.d.ts", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"lib/", | ||
"module.js", | ||
"module.d.ts" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -18,0 +18,0 @@ "readmeFilename": "README.md", |
@@ -12,3 +12,3 @@ # HTTP Service | ||
--- | ||
**`useHttpService`([config](https://axios-http.com/docs/req_config), [interceptors](https://github.com/axios/axios#interceptors))** | ||
**`useHttpService`**([config](https://axios-http.com/docs/req_config), [interceptors](https://github.com/axios/axios#interceptors)) | ||
@@ -41,3 +41,3 @@ | ||
], | ||
} | ||
}; | ||
@@ -85,6 +85,6 @@ export const { | ||
**`createApiServiceContainer`(httpConfig, httpInterceptors, serviceList)** | ||
**`createApiServiceContainer`**(`constructorsDict`, `httpConfig`, `httpInterceptors`) | ||
`httpConfig` and `httpInterceptors` contracts equals to `useHttpService` arguments.<br> | ||
`serviceList` is array of constructors, for example: | ||
`constructorsDict` is dictionary of constructors (key, value pairs), for example: | ||
```javascript | ||
@@ -96,6 +96,6 @@ // api.ioc.js | ||
const serviceList = [ | ||
const constructorsDict = { | ||
UserService, | ||
ProductService | ||
]; | ||
productService: ProductService | ||
}; | ||
``` | ||
@@ -115,6 +115,6 @@ | ||
export const container = createApiServiceContainer(serviceList, config) // interceptors is optional param | ||
export const container = createApiServiceContainer(constructorsDict, config) // interceptors is optional param | ||
``` | ||
___ | ||
**`BaseService`(httpService)** | ||
**`BaseService`**(`httpService`) | ||
@@ -121,0 +121,0 @@ Is class for inheritance and provide to your own classes context http methods and `setHeader` method. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12683
179