@selfcommunity/api-services
Version:
Client api for SelfCommunity.
57 lines (50 loc) • 2.13 kB
TypeScript
import { BaseSearchParams, SCPaginatedResponse } from '../../types';
import { SCLocalityType } from '@selfcommunity/types';
import { AxiosRequestConfig } from 'axios';
export interface LocalityApiClientInterface {
getLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
searchLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
}
/**
* Contains all the endpoints needed to manage localities.
*/
export declare class LocalityApiClient {
/**
* This endpoint retrieves the list of available localities.
* @param params
* @param config
*/
static getLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
/**
* This endpoint searches localities
* @param params
* @param config
*/
static searchLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
}
/**
*
:::tip Locality service can be used in the following way:
```jsx
1. Import the service from our library:
import {LocalityService} from "@selfcommunity/api-services";
```
```jsx
2. Create a function and put the service inside it!
The async function `getLocalities` will return the paginated list of localities.
async getLocalities() {
return await LocalityService.getLocalities();
}
```
```jsx
If you need to customize the request, you can add optional config params (`AxiosRequestConfig` type).
1. Declare it(or declare them, it is possible to add multiple params)
const headers = headers: {Authorization: `Bearer ${yourToken}`}
2. Add it inside the brackets and pass it to the function, as shown in the previous example!
```
:::
*/
export default class LocalityService {
static getLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
static searchLocalities(params?: BaseSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCLocalityType>>;
}