All Projects β†’ brainbreaker β†’ Rest And Go

brainbreaker / Rest And Go

Licence: mit
A basic online store REST API written with Golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Rest And Go

Omdb Graphql Wrapper
πŸš€ GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-54.08%)
Mutual labels:  api, server
Ins sandstorm
[INS] Config setting for our sandstorm server
Stars: ✭ 61 (-37.76%)
Mutual labels:  api, server
Nodejs
Everything related to the Node.js ecosystem for the commercetools platform.
Stars: ✭ 47 (-52.04%)
Mutual labels:  api, ecommerce
Orion Core
The next generation Terraria Server API.
Stars: ✭ 28 (-71.43%)
Mutual labels:  api, server
Appy Backend
A user system to bootstrap your app.
Stars: ✭ 96 (-2.04%)
Mutual labels:  api, server
Nodemcu Espress
Ultra-Lightweight and modular Node.js express like http server for NodeMCU. web - ESP8266
Stars: ✭ 39 (-60.2%)
Mutual labels:  api, server
Sechub
SecHub - one central and easy way to use different security tools with one API/Client
Stars: ✭ 52 (-46.94%)
Mutual labels:  api, server
Impress
Enterprise application server for Node.js and Metarhia private cloud ⚑
Stars: ✭ 634 (+546.94%)
Mutual labels:  api, server
Generator Swiftserver
WARNING: This repository is no longer maintained
Stars: ✭ 64 (-34.69%)
Mutual labels:  api, server
Unvault
πŸ“¦ A minimal layer for node that allows results of time-consuming tasks to be stored.
Stars: ✭ 63 (-35.71%)
Mutual labels:  api, server
Orbit Db Http Api
A HTTP API Server for the OrbitDB distributed peer-to-peer database
Stars: ✭ 17 (-82.65%)
Mutual labels:  api, server
Go Whatsapp Rest
Go WhatsApp Implementation in REST API
Stars: ✭ 86 (-12.24%)
Mutual labels:  api, server
Deno Drash
A REST microframework for Deno's HTTP server with zero 3rd party dependencies.
Stars: ✭ 795 (+711.22%)
Mutual labels:  api, server
Dito
Dito.js is a declarative and modern web framework with a focus on API driven development, based on Objection.js, Koa.js and Vue.js – Released in 2018 under the MIT license, with support by Lineto.com
Stars: ✭ 44 (-55.1%)
Mutual labels:  api, server
Build
TeaWeb-ε―θ§†εŒ–ηš„Webδ»£η†ζœεŠ‘γ€‚DEMO: http://teaos.cn:7777
Stars: ✭ 656 (+569.39%)
Mutual labels:  api, server
Grocerystore With Server
Grocery Store with server integration
Stars: ✭ 51 (-47.96%)
Mutual labels:  api, ecommerce
Ponzu
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
Stars: ✭ 5,373 (+5382.65%)
Mutual labels:  api, server
Spock
Another Haskell web framework for rapid development
Stars: ✭ 623 (+535.71%)
Mutual labels:  api, server
Gophergameserver
πŸ† Feature packed, easy-to-use game server API for Go back-ends and Javascript clients. Tutorials and examples included!
Stars: ✭ 61 (-37.76%)
Mutual labels:  api, server
Cross Platform Node Guide
πŸ“— How to write cross-platform Node.js code
Stars: ✭ 1,161 (+1084.69%)
Mutual labels:  api, server

rest-and-go(Not maintained actively)

A basic online store API written to learn Go Programming Language

This API is a pretty basic implementation of an online(e-commerce) store.

  • You can perform basic CRUD(CREATE, READ, UPDATE and DELETE) operations
  • SEARCH on a predefined database of products
  • Only Authenticated users can Add, Update and Delete products from database
  • Authentication is based on JWT(JSON web Tokens) Tokens
  • API is backed by a predefined Mongo DB database hosted on mLab
  • This API also lives on Heroku - https://gruesome-monster-22811.herokuapp.com/

See API Documentation and Usage below on how to use it.

Directory Structure

rest-and-go/
    |- Godeps/             - Contains info about all dependencies of the project
    |- store/              - Contains main API logic files 
        |- controller.go  - Defines methods handling calls at various endpoints
        |- model.go       - User and Product models
        |- repository.go  - Methods interacting with the database
        |- router.go      - Defines routes and endpoints
    |- vendor/             - Dependency packages, necessary for deployment
    |- .gitignore
    |- LICENSE
    |- Procfile             - Procfile for herkou deployment
    |- README.md
    |- dummyData.js         - Script to populate local mongodb with dummy data
    |- main.go              - Entry point of the API
  

Setup

Golang Development Setup

You can use this bash script to automate the Golang development setup - https://github.com/canha/golang-tools-install-script

Steps

  1. Download the repository using wget wget https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh
  2. According to the OS you're on
    • Linux 64 bit -> bash goinstall.sh --64
    • Linux 32 bit -> bash goinstall.sh --32
    • macOS -> bash goinstall.sh --darwin

You can also follow the official docs of installation if you want to know the complete process.

Project setup

  1. Clone the repository in your $GOPATH/src/ directory. If you have used the bash script for setup, your $GOPATH variable should point to $HOME/go
  2. Follow the steps 2-6 only if you have to set-up databse by yourself. The MongoDB database is hosted on mLab free trial account for now and might expire. In that case, you'll need the steps below.
  3. To run project locally, Install Mongo DB - https://www.mongodb.com/download-center?jmp=nav#community
  4. After installing Mongo DB, start it's server by typing mongod in Terminal.
  5. Open a new tab in terminal and type mongo < dummyData.js to insert the dummmy product data.
  6. Open file store/repository.go, find the SERVER variable and replace the URL.
const SERVER = "http://localhost:27017"
  1. Last thing required to run the project, install all the go dependencies
// Library to handle jwt authentication 
$ go get "github.com/dgrijalva/jwt-go"

// Libraries to handle network routing
$ go get "github.com/gorilla/mux"
$ go get "github.com/gorilla/context"
$ go get "github.com/gorilla/handlers"

// mgo library for handling Mongo DB
$ go get "gopkg.in/mgo.v2"

Yay! Now we're ready to run the API πŸŽ‰
8. Type export PORT=8000 in Terminal and open http://localhost:8000 in your browser to see the products.

API Documentation and Usage

It is recommended to install some extension to beautify JSON(like JSON Formatter) if you're trying in a browser.

Important - Don't forget to define $PORT in your shell variables.
Example: export PORT=8000

BASE_URL = "http://localhost:$PORT"
'OR'
BASE_URL = https://gruesome-monster-22811.herokuapp.com/

1. View Products

  • Endpoint Name - Index
  • Method - GET
  • URL Pattern - /
  • Usage
    • Open BASE_URL in browser
    • Terminal/CURL
    curl -X GET BASE_URL
    
  • Expected Response - JSON containing all the products in database
  • Example Screenshot

2. View Single Product

  • Endpoint Name - GetProduct
  • Method - GET
  • URL Pattern - /products/{id}
  • Usage
    • Open BASE_URL/products/{id} in browser
    • Terminal/CURL
curl -X GET BASE_URL/products/{id} 
  • Expected Response - Product with the {id} in database
  • NOTE - There are only six(6) ids in the database, so 1 <= {id} <= 6
  • Example Screenshot

3. Search Product

  • Endpoint Name - SearchProduct
  • Method - GET
  • URL Pattern - /Search/{query}
  • Usage - Browser OR curl
  • BROWSER
    • Open BASE_URL/Search/{query} in browser
    • Terminal/CURL
    curl -X GET BASE_URL/Search/{query}
    
  • Expected Response - Products matching the search query
  • Example Screenshot

4. Authentication

For Adding, Updating and Deleting products from database you must send a JWT token in Authentication header.

  • Endpoint Name - GetToken
  • Method - POST
  • URL Pattern - /get-token
  • Usage - CURL OR POSTMAN ONLY
    • Terminal/CURL
    curl -X POST \
    -H "Content-Type: application/json" \
    -d '{ username: "<YOUR_USERNAME>", password: "<RANDOM_PASSWORD>"}' \
    BASE_URL/get-token
    
  • Expected Response - A JWT Authentication Token as shown below
  • Example Screenshot

5. Add Product

  • Endpoint Name - AddProduct
  • Method - POST
  • URL Pattern - /AddProduct
  • Usage - CURL OR POSTMAN ONLY
    • Terminal/CURL
    curl -X POST \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{ "_id": 11, 
        "title": "Memes",
        "image": "I am selling memes, hehe.",          
        "price": 1,
        "rating": 5
        }' \
    BASE_URL/AddProduct
    
  • Expected Response - Addition successful without any error message. Check the logs in Terminal window which is running server.
  • Example Screenshot

6. Update Product

  • Endpoint Name - UpdateProduct
  • Method - PUT
  • URL Pattern - /UpdateProduct
  • Usage - CURL OR POSTMAN ONLY
    • Terminal/CURL
    curl -X PUT \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{ "ID": 14, 
        "title": "Memes",
        "image": "I am not selling memes to you, hehe.",          
        "price": 1000,
        "rating": 5
        }' \
    BASE_URL/UpdateProduct
    
  • Expected Response - Update successful without any error message. Check the logs in Terminal window which is running server.
  • Example Screenshot

7. Delete Product

  • Endpoint Name - DeleteProduct
  • Method - DELETE
  • URL Pattern - /deleteProduct/{id}
  • Usage - CURL OR POSTMAN ONLY
    • Terminal/CURL
    curl -X DELETE \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    BASE_URL/deleteProduct/{id}
    
  • Expected Response - Deletion successful without any error message. Check the logs in Terminal window which is running server.
  • Example Screenshot

TODO

  • [ ] Write unit tests to test every method
  • [ ] Improve the code by proper exception handling
  • [ ] Add repository badges like TravisCI, Better Code, Codacy etc.
  • [ ] Create a REST API server project using this package as a boilerplate
  • [ ] User and roles management
  • [ ] Session management using JWT tokens
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].