Skip to content

Commit be2255f

Browse files
authored
Merge pull request #7 from sharathkumaranbu/master
Different Readme for npm
2 parents c42898e + d3d9c88 commit be2255f

File tree

2 files changed

+116
-9
lines changed

2 files changed

+116
-9
lines changed

README

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# topcoder-bus-api-wrapper
2+
3+
Wrapper library for Topcoder Bus API
4+
5+
## How to use this Wrapper
6+
7+
Install Topcoder bus api wrapper as
8+
9+
```
10+
npm i topcoder-bus-api-wrapper
11+
```
12+
13+
Create an instance of this wrapper with the configuration variables listed below
14+
15+
```
16+
const busApi = require('topcoder-bus-api-wrapper')
17+
const busApiClient = busApi(_.pick(config,
18+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
19+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
20+
'KAFKA_ERROR_TOPIC']))
21+
```
22+
23+
**Configuration / Environment variables:**
24+
25+
* *Auth0 related variables*
26+
* AUTH0_URL
27+
* AUTH0_AUDIENCE
28+
* TOKEN_CACHE_TIME (optional)
29+
* AUTH0_CLIENT_ID
30+
31+
* BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
32+
* KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
33+
34+
Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments
35+
36+
E.g.
37+
38+
```
39+
busApiClient
40+
.getTopics()
41+
.then(result => console.log(result.body, result.status))
42+
.catch(err => console.log(err))
43+
44+
await busApiClient.postEvent(reqBody)
45+
```
46+
47+
Refer `index.js` for the list of available wrapper functions
48+
49+
## Documentation for Bus API wrapper methods
50+
51+
All URIs are relative to **BUSAPI_URL** configuration variable.
52+
53+
Method | HTTP request | Description
54+
------------- | ------------- | -------------
55+
[**postEvent**](docs/EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
56+
[**postError**](docs/EventsApi.md#postError) | **POST** /bus/events | Post error event to the message bus. This method is same as postEvent except that topic will be set by the wrapper itself.
57+
[**getHealth**](docs/HealthchecksApi.md#getHealth) | **GET** /bus/health | Check API is healthy.
58+
[**headHealth**](docs/HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.
59+
[**clearPlaceholdersCache**](docs/PlaceholdersApi.md#clearPlaceholdersCache) | **DELETE** /bus/placeholders | Clear placeholders cache.
60+
[**createService**](docs/ServiceApi.md#createService) | **POST** /bus/services | Create a service.
61+
[**createServicePayload**](docs/ServiceApi.md#createServicePayload) | **POST** /bus/services/{serviceName}/payloads | Create the service payload.
62+
[**deleteService**](docs/ServiceApi.md#deleteService) | **DELETE** /bus/services/{serviceName} | Delete the service.
63+
[**deleteServicePayload**](docs/ServiceApi.md#deleteServicePayload) | **DELETE** /bus/services/{serviceName}/payloads/{payloadName} | Delete the service payload.
64+
[**getService**](docs/ServiceApi.md#getService) | **GET** /bus/services/{serviceName} | Get the service.
65+
[**getServicePayload**](docs/ServiceApi.md#getServicePayload) | **GET** /bus/services/{serviceName}/payloads/{payloadName} | Get the service payload.
66+
[**getServicePayloads**](docs/ServiceApi.md#getServicePayloads) | **GET** /bus/services/{serviceName}/payloads | Search the service payloads.
67+
[**getServices**](docs/ServiceApi.md#getServices) | **GET** /bus/services | Get all services.
68+
[**headService**](docs/ServiceApi.md#headService) | **HEAD** /bus/services/{serviceName} | Get only response status and headers information but no response body for the endpoint.
69+
[**headServicePayload**](docs/ServiceApi.md#headServicePayload) | **HEAD** /bus/services/{serviceName}/payloads/{payloadName} | Get only response status and headers information but no response body for the endpoint.
70+
[**headServicePayloads**](docs/ServiceApi.md#headServicePayloads) | **HEAD** /bus/services/{serviceName}/payloads | Get only response status and headers information but no response body for the endpoint.
71+
[**headServices**](docs/ServiceApi.md#headServices) | **HEAD** /bus/services | Get only response status and headers information but no response body for the endpoint.
72+
[**patchService**](docs/ServiceApi.md#patchService) | **PATCH** /bus/services/{serviceName} | Partially update the service.
73+
[**patchServicePayload**](docs/ServiceApi.md#patchServicePayload) | **PATCH** /bus/services/{serviceName}/payloads/{payloadName} | Partially update the payload.
74+
[**updateService**](docs/ServiceApi.md#updateService) | **PUT** /bus/services/{serviceName} | Update the service.
75+
[**updateServicePayload**](docs/ServiceApi.md#updateServicePayload) | **PUT** /bus/services/{serviceName}/payloads/{payloadName} | Update the service payload.
76+
[**getTopics**](docs/TopicsApi.md#getTopics) | **GET** /bus/topics | Get topics.
77+
[**headTopics**](docs/TopicsApi.md#headTopics) | **HEAD** /bus/topics | Get only response status and headers information but no response body for the endpoint.
78+
79+
## Authorization
80+
81+
Bus API wrapper internally generates a **JWT token using Auth0 credentials** and pass it in the `Authorization` header.
82+
83+
## Running tests
84+
85+
Following environment variables need to be set up before running the tests
86+
87+
```
88+
- TEST_AUTH0_URL
89+
- TEST_AUTH0_AUDIENCE
90+
- TEST_AUTH0_CLIENT_ID
91+
- TEST_AUTH0_CLIENT_SECRET
92+
- TEST_BUS_API_URL
93+
- TEST_KAFKA_ERROR_TOPIC
94+
```
95+
96+
Refer to Step # 2 in [this section](#how-to-use-this-wrapper) to learn more about the configuration variables.
97+
98+
To run the tests alone, execute the command
99+
100+
```
101+
npm run test
102+
```
103+
104+
To run tests with coverage report, execute the command
105+
106+
```
107+
npm run cov
108+
```

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ const busApiClient = busApi(_.pick(config,
2323

2424
**Configuration / Environment variables:**
2525

26-
*Auth0 related variables:*
27-
- AUTH0_URL
28-
- AUTH0_AUDIENCE
29-
- TOKEN_CACHE_TIME (optional)
30-
- AUTH0_CLIENT_ID
31-
32-
- BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
33-
- KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
34-
26+
* *Auth0 related variables*
27+
* AUTH0_URL
28+
* AUTH0_AUDIENCE
29+
* TOKEN_CACHE_TIME (optional)
30+
* AUTH0_CLIENT_ID
31+
32+
* BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
33+
* KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
3534

3635
3. Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments
3736

0 commit comments

Comments
 (0)