This project provides a simple SDK client that interacts with a Post API to manage posts. It includes functionalities such as creating, reading, updating, and deleting posts using a REST API. The SDK leverages a service/repository pattern and integrates environment variable management through .env
files.
This SDK provides a simple interface for interacting with multiple services.
The SDK has only one service for now, PostsService
, but it's written in a modular way so other modules can be easily added later. The client connects to a REST API, and the base URL for the API is configurable using environment variables.
To install and use the SDK, follow these steps:
-
Clone the repository:
git clone https://github.com/mvsantos013/sdk-chall
-
Navigate to the project directory:
cd sdk-chall
-
Install dependencies:
npm install
Set up environment variables: Create a .env and .env.test file in the root of the project and set the API_BASE_URL variable:
API_BASE_URL=https://jsonplaceholder.typicode.com
The SDK client provides a method to instantiate the PostsService. The client uses the Singleton pattern to ensure a single instance of the PostsService is created. You can access the PostsService by calling the postsService method with the apiBaseUrl argument.
import sdkClient from "./src/index";
const apiBaseUrl = process.env.API_BASE_URL;
const postsService = sdkClient.postsService(apiBaseUrl);
postsService.getPosts().then((posts) => {
console.log(posts);
});
npm run test