Git Product home page Git Product logo

rest_echo's Introduction

SIMPLE REST API WITH ECHO FRAMEWORK

Setup REST API with Echo Framework, Postgre and Messaging.

Package Dependencies

Below is the packages used by this project

Configs

Config file located in config.yaml on the root of project.

ORM

Ready for Postgres and MySQL. Connection function located at db/gorm/gorm.go. Those function called in main.go.

CRUD Functionality

Base CRUD function are located in models/orm/orm.go. Example implementation within each model can be found at models/user.go

Models

Models located in models. All models should inherit BaseModel struct in models/base.go. BaseModel struct are holding default tables attribute. Another attributes specific to each model should defined as struct in each model file (i.e models/user.go)

Request Validator

Currently there is two validation function for request.

Validate JSON Body

Function for validate this kind of request is ValidateRequest(c echo.Context, rules govalidator.MapData, data interface{}) map[string]interface{}, located in api/handlers/generalHandlers

Validate URL Query String

Function for validate this kind of request is ValidateQueryStr(c echo.Context, rules govalidator.MapData, data interface{}) map[string]interface{}, located in api/handlers/generalHandlers

Limitation

You cannot use single validation for both query string and/or request body

Logger

Logrus are wrapped within modules/logger/logger.go under logger package. This wrapper also implement file rotator.

Default rotator time is every one day and only kept for seven days of log.

Example implementation can be found at api/middlewares/logMiddlewares.go

Unit Test

This unit test is for testing each endpoint and response. All test file located in tests folder. You can run a test with

go test tests/*_test.go

Run with Docker

  • Install Docker
  • Clone this repo
  • Create another container for Postgre, and put in the same docker network (i.e my-shared-network). You can use my support container
  • Run docker-compose up --build on project root, and make sure to check it if its run well with docker-compose ps, you should see like this below
Imans-MacBook-Air:disbursement iman$ docker-compose ps
       Name                     Command               State           Ports
------------------------------------------------------------------------------------
<your_project_folder>_api_1   /bin/sh -c dep ensure && g ...   Up      0.0.0.0:8000->8000/tcp
  • Test with your REST API tools for GET 0.0.0.0:8000/users, and you should see some JSON response.

References When Building This Project

Insomania (RESTAPI Client) Workspace

If you use Insomnia you can import sample workspace from INSOMNIA-WORKSPACE.json.

rest_echo's People

Contributors

rimantoro avatar

Watchers

James Cloos 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.