Giter Site home page Giter Site logo

pokeguess-backend's Introduction

PokeGuess Backend

Description

This is a backend API server written with Nest.js. This application is suggested to be used with the frontend web application here

Usage

Before starting the app, remember to add a .env file and you can reference the .env.example in the repo

To Start Locally

yarn && yarn start

To build and run

yarn build && yarn start:prod

To Test

yarn test

add --coverage flag if you wanna check coverage

Current Coverage

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 99.15 100 100 99.04
pokeGuess 100 100 100 100
pokeGuess.controller.ts 100 100 100 100
pokeGuess.repository.ts 100 100 100 100
pokeGuess.service.ts 100 100 100 100
pokeGuess/transformers 100 100 100 100
pokemonTransformer.ts 100 100 100 100
questionTransformer.ts 100 100 100 100
pokeGuess/utils 92.85 100 100 90.9
randomPokemonHelper.ts 92.85 100 100 90.9 13

Run on Docker (Dockerised production build)

yarn compose

if your interested in the command checkout package.json

API Design

The basic design is demonstrated below.

Request -> Controller -> Service -> Repository
  1. Request will first hit controller. Then any information will be passed to the Service directly

  2. In Service, that's where I put the logics of how the information should be process. Data will be gathered from Repository and transformers will be injected here and transform to desire response.

  3. Repository is solely designed to isolate API callings from the pokeapi. In normal use cases, this repository is used to query the DB and return raw data. No/Minimal logic should be left here.

Detail Api - /pokeguess route

GET /question

This route is as simple as it is named. This route will return a trivia question with random pokemons.

Response

{
  "pokemonId": 1,
  "pokemonName": "bulbasaur",
  "pokemonCry": "https://raw.githubusercontent.com/PokeAPI/cries/main/cries/pokemon/latest/1.ogg",
  "pokemonImg": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
  "pokemonNameList": [
    "venusaur","bulbasaur","caterpie","pidgeotto"
  ]
}

POST validate

This api require a request body of answer information which includes pokemon name of player's answer and pokemon id of the correct answer. Then it will validate the answer and response with the correct answer information and whether the player is correct

Body

{
  "pokemonId": 1,
  "answer": "bulbasaur"
}

Response

{
  "correct": true,
  "image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
  "pokemonName": "bulbasaur"
}

Swagger

A Swagger doc is generated when you start this application and it will be available at {Base_URL}/api

pokeguess-backend's People

Contributors

samor1014 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.