codemaniac-service-http
v1.0.0
Published
Codemaniac fork of microservice http service adapter
Readme
CodeManiac Service HTTP
A microservice for handling HTTP requests and responses as part of the CodeManiac project.
Features
- RESTful API endpoints
- Request validation and error handling
- Modular and scalable architecture
- It includes retry methods.
Getting Started
Prerequisites
- Node.js (or your project's runtime)
- npm or yarn
Installation
npm install @codemaniac-technologies/codemaniac-service-httpinit(config)
- init method takes config object which consist request server configuration.
config
Config object has below parameters
host: Host which request need to be sent.
port (optional): Port on which server is running
user (optional): Basic authentication username to use.
password (optional): Basic authentication password to use.
apiKey (optional): If you want to pass apiKey add header as codemaniac-apiKey.
throttleOptions (optional): Object with two parameters requestLimit for number of request retry and requestInterval on which interval request should retry.
get(path, options, context)
- This function is used for send get request with parameter explain below.
path
- path parameter consists path of the api. for example if you want to send request https://example.com/v1/demo then ur path will be /v1/demo
options
- options parameter is a object with below parameters:
- baseUrl: The url where on which we want to send request for example In above example https://example.com will be base url. Note: omit / at end if path is starting with /
- maxAttempts: this parameter defines maximum retry attempts. Default it is 1
- retryDelay: this parameter define wait time for delay. Default it is 200ms
- headers: this parameter consist all the request headers
- qs: this parameter consists query string object
post(path, options, context, body)
- This function is used for send post request with parameter explain below.
path
- path parameter consists path of the api. for example if you want to send request https://example.com/v1/demo then ur path will be /v1/demo
options
- options parameter is a object with below parameters:
- baseUrl: The url where on which we want to send request for example In above example https://example.com will be base url. Note: omit / at end if path is starting with /
- maxAttempts: this parameter defines maximum retry attempts. Default it is 1
- retryDelay: this parameter define wait time for delay. Default it is 200ms
- headers: this parameter consist all the request headers
body
- request body which needed to sent
post(path, options, context, body)
- This function is used for send post request with parameter explain below.
path
- path parameter consists path of the api. for example if you want to send request https://example.com/v1/demo then ur path will be /v1/demo
options
- options parameter is a object with below parameters:
- baseUrl: The url where on which we want to send request for example In above example https://example.com will be base url. Note: omit / at end if path is starting with /
- maxAttempts: this parameter defines maximum retry attempts. Default it is 1
- retryDelay: this parameter define wait time for delay. Default it is 200ms
- headers: this parameter consist all the request headers
body
- request body which needed to sent
request(context, options, body)
- This is generalized function is used for send any request with parameter explain below.
path
- path parameter consists path of the api. for example if you want to send request https://example.com/v1/demo then ur path will be /v1/demo
options
- options parameter is a object with below parameters:
- baseUrl: The url where on which we want to send request for example In above example https://example.com will be base url. Note: omit / at end if path is starting with /
- maxAttempts: This parameter defines maximum retry attempts. Default it is 1
- retryDelay: This parameter define wait time for delay. Default it is 200ms
- headers: This parameter consist all the request headers
- method: This is request method parameter
body
- request body which needed to sent
