Giter Site home page Giter Site logo

deck-api's Introduction

Deck API

Project Overview

This project provides a simple RESTful API for working with a deck of cards. The API allows users to create a deck, shuffle a deck, and draw cards from a deck.

The project is structured as follows:

.
├── cmd
│ └── deck
│   └── main.go
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── pkg
│ ├── responses
│ │ └── deck_api_responses.go
│ ├── deck
│ │ ├── deck.go
│ │ ├── deck_test.go
│ │ ├── draw.go
│ │ ├── draw_test.go
│ │ ├── open.go
│ │ └── open_test.go
│ ├── server
│ │ ├── server.go
│ │ └── server_test.go
│ └── service
│   └── deck.go
├── go.mod
└── README.md

Logic Separation

graph TD
    A[Main Package Layer] --> B[Server Package Layer]
    B --> C[Service Package Layer]
    C --> D[Dedicated Package with Separate Logic]
Loading

Package Structure

  • cmd/deck: This package contains the main.go file which is the entry point of the application. It initializes the necessary dependencies, creates an instance of the server, and starts the server to listen for incoming requests.

  • docs: This package contains the documentation for the API, including the swagger.yaml and swagger.json files that describe the API endpoints and their parameters. The package also includes a docs.go file that can be used to serve the documentation as a web page.

  • pkg/responses: This package contains response structs that are returned by the API endpoints. These structs are used to marshal responses in JSON format.

  • pkg/deck: This package provides the core functionality for working with a deck of cards. It includes methods for creating a deck, shuffling a deck, and drawing cards from a deck. The package also includes corresponding test files.

  • pkg/server: This package provides the server layer of the application. It includes the HTTP server initialization and routing definitions. The package also includes corresponding test files.

  • pkg/service: This package provides the service layer of the application. It includes methods for extracting, processing, and validating URL parameters and request bodies. Once validated, requests are forwarded to the appropriate methods in separate packages.

Dependencies

This project depends on the following external libraries:

  • gin-gonic/gin: A popular HTTP router and dispatcher for building RESTful APIs.
  • stretchr/testify: A testing toolkit for writing unit tests and assertions in Go.
  • google/uuid: A package for generating and parsing UUIDs in Go.
  • gin-contrib/swagger: A middleware for automatically generating RESTful API documentation with Swagger 2.0 for Gin web framework.

Build and Run

  • To build and run the project locally, use the following commands:

    • Build
      go build ./cmd/deck
      
    • Run
      ./deck
      
  • To build and run the project locally, use the following commands:

    • Build
      docker build -t deck-api .
      
    • Run
      docker run -p 8080:8080 deck-api
      

Principles for dealing with the development of this repository

  1. Initialization of major dependencies should be performed in the main package. This ensures that the server is properly configured before it starts processing requests.
  2. API routing should be carefully defined, including the endpoints that can be accessed within the server layer. Different group handlers should be registered to ensure that requests are properly handled and routed to the appropriate services.
  3. The service layer should be responsible for extracting, processing, and validating URL parameters and request bodies. Once validated, requests should be forwarded to the appropriate methods in separate packages.
  4. To handle incoming requests with validated parameters, an appropriate package should be built to process these requests efficiently and effectively.
  5. Documentation should be maintained throughout the development process, including API documentation and code comments, to ensure that the application is understandable and maintainable.

API Documentation

The API is documented using Swagger, which provides an interactive interface for exploring the API and its endpoints. The Swagger documentation is accessible at /docs. To view the documentation, navigate to http://localhost:8080/swagger/index.html in your web browser. The Swagger interface allows you to view the API specification, test endpoints, and experiment with different request and response payloads.

deck-api's People

Contributors

ashutosh00710 avatar

Watchers

 avatar  avatar

deck-api's Issues

Create a basic outlet of project

Make an initial folder structure to start with the API implementation.

Targets:

  • Basic folder structure and Hello, World Program running

Add logic to create a deck

Targets:

  • /deck should return 52 cards by default
  • /deck with cards query param should receive card codes and create a custom deck
  • it should also receive shuffle as a query param and should shuffle the deck if the value is true

Add draw deck logic

Targets:

  • /draw/:id should draw a card and return it as a response.
  • /draw/:id should receive an optional count query param, to draw n number of cards.
  • in case the value n is incorrect, an error should be returned.

Create a basic flow of api

Targets:

  • Setup Gin
  • Create a route group deck
  • Requesting on /deck should return {"message": "success"}

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.