Rest Api server, написанный на Golang

Задача: создать простой REST API, который будет позволять получать информацию про пиццу.

Шаг 1. Желаемый функционал.

Хотим собрать простой веб-сервер, который будет взаимодействовать с окружающим миром через API, поддерживающий REST

Шаг 1.1 Виды запросов, поддерживаемые API

Будет существовать и поддерживать 2 запроса:

  • http://localhost:8080/pizzas - возвращает json со всеми пиццами в наличии
  • http://localhost:8080/pizza/{id} - возвращает информацию про пиццу с id в случае, если она имеется в наличии или сообщает клиенту, что такой пиццы нет.

Шаг 2. Реализация

  • Создаём проект mkdir rest_api_pizza
  • Сразу инициализируем go mod rest_api_pizza

Шаг 2.1 Маршрутизатор и исполнители

Маршрутизатор (router) - это экземпляр, который имеет внутренний функционал, заключающийся в следующем:

  • принимает на вход адрес запроса (по сути это строка http://localhost:8080/pizzas) и вызывает исполнителя, который будет ассоциирован с этим запросом.

Исполнитель (handler) - это функция/метод, который вызывается маршрутизатором.

Для того, чтобы удобно работать с маршрутизатором и не писать с нуля, будем использовать готовую библиотеку github.com/gorilla/mux: go get -u github.com/gorilla/mux

Similar Resources

Go Twitter REST and Streaming API v1.1

go-twitter go-twitter is a Go client library for the Twitter API. Check the usage section or try the examples to see how to access the Twitter API. Fe

Dec 28, 2022

Unofficial Go SDK for GoPay Payments REST API

Unofficial Go SDK for GoPay Payments REST API Installation go get https://github.com/apparently-studio/gopay-go-api Basic usage client := gopay.NewCl

Nov 18, 2022

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs

PnPjs is a fluent JavaScript API for consuming SharePoint and Microsoft Graph REST APIs in a type-safe way. You can use it with SharePoint Framework,

Dec 23, 2022

Use Google REST api to extract your personal Photo Library

Photo Go A better approach to extracting your photos from Google to your personal cloud. I'm moving my photos out of Google to a Synology NAS. create

Dec 7, 2021

Go REST API for movies

Greenlight API Greenlight is an api, i implemented by following the book Let's Go Further by Alex Edwards If you like what you see please consider buy

Jul 17, 2022

Hassle-free REST API testing for Go

melatonin melatonin is a fluent, flexible REST API testing library for Go. It provides many of the benefits of a domain-specific test language but wit

Jan 8, 2022

REST API for "MovieShare".

movieshare_api Repository for backend of project "MovieShare". MovieShare API An awesome API for project "MovieShare". Requirements See modules list i

Apr 14, 2022

Stq - Simple Task Queue with REST API

stq Simple Tasks Queue with HTTP API Environments list: Variable Value BACKEND m

Jan 5, 2022

Rest API to get KVB departures - Written in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeger

KVB API Rest API to get upcoming departures per KVB train station Implemented in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeg

May 7, 2022
Todosappdeploy - Todos REST API build using echo server

Todos Week 5 - Project Todo List Todos REST API build using echo server. The cod

Jan 14, 2022
Backend REST-api server for hyperism

hyperism-go Backend REST-api server for hyperism Quick Overview Step 1. Deploy REST API, Database and IPFS git clone https://github.com/hyperism/hyper

Apr 30, 2022
Triangula-api-server - API server for processing images with Triangula

Triangula API server Minimalistic API server that calculates and serves artistic

Jan 10, 2022
go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface

go-whatsapp-rest-API go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface Multi-devices (MD) Support. This ver

Dec 15, 2022
Api-product - A basic REST-ish API that allows you to perform CRUD operations for Products

Description A basic REST-ish API that allows you to perform CRUD operations for

Jan 3, 2022
Lol-champions-api - A REST API app for CRUD' ing informations related to League of Legends champions, written with Go

LOL-CHAMPIONS-API Just a REST API app for CRUD' ing informations related to Leag

Mar 17, 2022
Golang client for PayPal REST API

Go client for PayPal REST API Coverage POST /v1/oauth2/token POST /v1/identity/openidconnect/tokenservice GET /v1/identity/openidconnect/userinfo/?sch

Dec 25, 2022
A rest-api that works with golang as coin portfolio

Koinfolio A rest-api that works with golang as coin portfolio Technical Details Golang/Gin is used as application framework MongoDB is database Usage

Jun 1, 2022
Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

May 7, 2022
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

Feb 14, 2022