This application is developed using Next.js and it generates color swatches via API and displayed in frontend. You can generate more colors just by clicking "Generete Colors" button. The purpose of this task is to display code extensibility.
- npm i
- npm run dev
-
Add an interface in "src/types/color-space.d.ts" file.
export interface ColorSpaceInterface { red: number; blue: number; green: number; type: string; }
-
Declare a class named as BRGB in "src/pages/api/get-random-colors.ts" file.
class BRGB implements Handler<ColorSpaceInterface> { Encode(): ColorSpaceInterface { return { blue: getRandomNumbers(0, 1000), green: getRandomNumbers(0, 1000), red: getRandomNumbers(0, 1000), type: 'brgb' } } }
-
Add previously declared class to handlers inside Controllers which is located in "src/pages/api/get-random-colors.ts" file.
That's it you can check the response in Network Tab in developer console or add a condition in frontend to render the color.
private handlers: Handler<any>[] = [..., new BRGB()];