Code Monkey home page Code Monkey logo

kojimachi's Introduction

Kojimachi ๐Ÿง

User service API ๐Ÿ›ฐ๏ธ

This is a simple node application which runs an express server. The API currently supports /login and /user routes, which allow for JWT authentication and user management respectively. Using this API, you can perform CRUD operations against a user database, all secured using a JWT auth process.

This repository also includes a Postman collection to demo all the core functionality of the API, as well as unit test coverage of all the requirements for the service.

Current implementation of the /login service will always generate a valid JWT token to authenticate requests for the /user service. In future, the /login API can be extended to require a valid username & password to allow for validation prior to granting the JWT token and prevent unwanted access.

Setup ๐Ÿ”—

To run, first clone the repository and install dependencies with npm i.

Set a secure JWT secret key in src/JWTconfig.js โ€“ currently containing a placeholder value.

Create a .env file in the root of the project, and configure the following values according to your preference and local postgres settings, eg. PORT=1337.

PORT=1337
DB_USER=kojimachi
DB_HOST=localhost
DB_NAME=postgres
DB_PASSWORD=hunter2

note: This setup assumes that the user database schema and tables have already been setup locally. If not, create a simple psql table with the following spec:

CREATE TABLE users (
id UUID PRIMARY KEY,
name VARCHAR(256) NOT NULL,
email VARCHAR(256) NOT NULL,
password VARCHAR(256) NOT NULL
);

Running ๐Ÿ

To run the application, run npm start. This will compile the app code, built to /dist, and start dist/server.js. Confirm in the console that the server is running on the port you specified in .env.

Use ๐ŸŽฒ

While the server is running, you can interact with the API. There is a Postman Collection included, /Kojimachi_User_API_test.postman_collection.json, that has examples of the standard API functions. Please make sure that you first authenticate and include the JWT as a part of each request.

The Authorization header will need to be set in the Postman requests with the JWT that is generated when you make the POST request to /login

Development ๐Ÿง‘โ€๐Ÿ’ป

To extend this API, future routes should be created within the routes directory. You can use the existing user routes as a template. Similarly, controllers are within controllers directory.

To extend the user service, update the controllers/UserController.ts file with new services. If the service is updated, please also include updates to the Postman collection so that it maintains feature parity and accurately reflects the usage of the API.

Schema validation is handled using joi. The user schema is defined at src/schemas/user.ts, and contains the validation and error handling messages for each property.

Testing ๐Ÿ‘ฉโ€๐Ÿ”ฌ

Unit tests are written using jest and supertest. The current functionality should currently be covered by existing unit tests, but new tests can be created within src/__tests__.

Run the test suite with npm test. This will also attempt to build & start the server first in case it is not already running.

kojimachi's People

Contributors

evvn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.