Giter Site home page Giter Site logo

omar391 / go-lang-rest-api-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 12 KB

This repository demonstrates the usage of the GO Lang REST API demo using the GIN framework. It also demonstrates how to deploy using docker-compose and GitHub actions.

Dockerfile 3.32% Go 96.68%
docker-compose api-security gin github-actions go-rest-api golang

go-lang-rest-api-demo's Introduction

Rest API using GO-Lang (usings clinics datasets)

⭐ For API we are using GIN http server.
⭐ Instead of database we are using JSON files in the data directory.
⭐ Essentially it load info about some clinics from remote url(set in the config toml), and publish them in an online searchable APIs.
⭐ We have demonstrated how to use security related headers for the endpoints.
⭐ Set-up docker-compose for easier deployments.
⭐ Set-up GitHub actions for CI purposes.
⭐ Included TEST suites
⭐ Included POSTMAN collections for easier testing.


POSTMAN API testing:

image


How to config

  • API search data are stored in following configs:
    • data/dental-clinics.json
    • data/vet-clinics.json
  • HTTP configurations (port, data-states) are in the toml file: ./conf.d/app.toml

API Security

We are taking following measures to ensure API security.

  • Setting up CORS security headers.
  • Setting up the 'attack-vector' headers
	//setting-up cors headers
	r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"GET"},
		AllowHeaders:     []string{"Origin"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
		MaxAge:           12 * time.Hour,
	}))

	//setting-up security headers
	r.Use(secure.New(secure.Config{
		FrameDeny:             true,
		ContentTypeNosniff:    true,
		BrowserXssFilter:      true,
		ContentSecurityPolicy: "default-src 'self'",
		IENoOpen:              true,
		ReferrerPolicy:        "strict-origin-when-cross-origin",
		//SSLProxyHeaders:       map[string]string{"X-Forwarded-Proto": "https"},
	}))

How to run

go build -o clinics-apis
./clinics-apis

How to run test

go clean -testcache  
go test ./...

How to find clinics

  • Use the POSTMAN collection JSON config and test there or you can use CURL.
  • Name, State and Availability criteria are supported. multiple criteria is supported too.

search it with criteria: name

curl http://127.0.0.1:5000/search?name=good

search it with criteria:state code/name

curl http://127.0.0.1:5000/search?state=ca
curl http://127.0.0.1:5000/search?state=California

search it with criteria:availability

curl http://127.0.0.1:5000/search?opening=12:00

search it with multiple criterias: name and state

curl http://127.0.0.1:5000/search?opening=12:00&name=center&state=ca

How to build docker images

docker-compose up

go-lang-rest-api-demo's People

Contributors

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