Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gin-api-demo

> 编程语言
Open source

An example of using the Gin framework in Go to create a JSON api with most of the core functionality a JSON api needs.

100 stars0 likes2 views
WebsiteGitHub

About

An example of using the Gin framework in Go to create a JSON api with most of the core functionality a JSON api needs.

Gin API Demo

An example of using the Gin framework in Go to create a JSON api with most of the core functionality a JSON api needs.

Installation

Install Glide

bash
curl https://glide.sh/get | sh
# or, on OSX
brew install glide

Check out the project and install it's dependencies

bash
$ go get github.com/sbecker/gin-api-demo
$ cd $GOPATH/src/github.com/sbecker/gin-api-demo/
$ glide install

How to run

In one terminal, run the server:

bash
$ cd $GOPATH/src/github.com/sbecker/gin-api-demo
$ go run main.go

In another terminal, try making requests:

bash
# Get all users as a non-admin - see only one user, with a subset of json attributes
$ curl -H 'Authorization: Bearer userA' -i http://localhost:8080/users
bash
# Get all users as an admin - see all users, with all json attributes
$ curl -H 'Authorization: Bearer userB' -i http://localhost:8080/users
bash
# Try to get all users as a non-user - get 401 Unauthorized
$ curl -i http://localhost:8080/users
bash
# Get a single user as a non-admin - see a subset of json attributes
$ curl -H 'Authorization: Bearer userA' -i http://localhost:8080/users/1
bash
# Get a single user as an admin - see a subset of json attributes
$ curl -H 'Authorization: Bearer userB' -i http://localhost:8080/users/1
bash
# Try to get a different user than self - get 404 Not Found
$ curl -H 'Authorization: Bearer userA' -i http://localhost:8080/users/2
bash
# Try to get a single user as a non-user, get 401 Unauthorized
$ curl -i http://localhost:8080/users/2

Done:

  • basic restful routing - GET /users, GET /users/:id
  • token authorization middleware
  • multi-level json serialization - display subset of json objects for non-admin users
  • separation of concerns - models, dao, resources, serializers, authorization
  • Glide for dependency management
  • UUIDs instead of integers for primary keys
  • Request-Id headers: Each API request has an associated request identifier
  • Cross-origin-request headers
  • Continuous integration
  • JSON logging
  • Env var configuration

Todo:

  • JWT token authorization
  • Pagination
  • Versioning
  • Standardize error responses
  • Integration with a real database
  • Swagger live documentation
  • Godoc
  • A test suite
  • Database migrations
  • Continuous deployment
  • Command line interface - run server, run migrations, start db console, etc
  • CLI with commands for migration, db drop/create/reset

Research:

  • Client side query language - a la GraphQL/Falkor/Datomic

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言