Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 2.86 KB

design.md

File metadata and controls

43 lines (28 loc) · 2.86 KB

TheOneSdk

This workspace has been generated by Nx, a Smart, fast and extensible build system.

Cloning and using this repo

Please see instructions in the README.md file in the root of this repo. You likely already know where to find this repo on GitHub, but for convenience here is the link: Erik-Brown-SDK

Project Approach

This workspace was created with Nx as an integrated monorepo. The reason for this was so that I could get some more experience working with Nx, and also because it saves me from having to set up configuration for TypeScript, Jest, ESLint, Prettier, and so on. Plus I was interested in figuring out how to publish packages to npm from a monorepo. Unfortunately it was published as CJS and not ESM, but I didn't want to waste too much time trying to figure out how to rework the configuration to rectify this.

Project Structure

Libraries and Apps are stored in the packages directory by default with Nx. This can be reconfigured to use whichever directories one prefers, but that was alright with me.

The actual SDK is stored in the packages/lotr-sdk directory. The contents of this directory are built and published to npm. There is also an app stored in packages/lotr-app that I used in order to test the SDK during development.

The SDK

The SDK itself is pretty straightforward. It contains types, constants, a test file, and the SDK class is stored in lotr-sdk.ts. The API Access Token must be passed in when creating a class instance, as this is used for all API calls through the SDK. For an improvement, I would have added the ability to provide an alternate base url value for the API, for a bit of flexibility. It didn't seem necessary at this time.

There's one private method that's used to actually fetch data from the API, and another public one with optional params that affect what sort of URL is passed for the actual call. This is constructed conditionally based on the params. I also decided to use an object for params so that it could be easier to expand on this to add support for pagination, sorting, and filtering.

I had considered just having the method to fetchMovieData be public and allowing a user to pass in the URL themselves, but I decided to go with the abstraction for now since use cases are limited and I thought it would be best to keep the SDK methods as the means of interacting with the API. This fetchMovieData method really would be converted to just a general fetchApiData if support for characters, quotes, etc. were to be added.

Conclusion

Thank you for taking the time to review this project! I hope you enjoyed it and I look forward to hearing your feedback.