SlideShare a Scribd company logo
Web-Services	In	Go	
U1am	Gandhi	
@U1amGandhi	
h1ps://in.linkedin.com/in/u1am-gandhi-0247aa21	
www.synerzip.com
Agenda	
•  REST	
•  Go	Advantage	
•  Web	service	example	
•  TesMng	
•  Securing	using	JWT	
•  HosMng
Web-service	
•  The	W3C	defines	a	Web	service	generally	as:	
													a	so%ware	system	designed	to	support	
interoperable	machine-to-machine	interac7on	
over	a	network.
RESTful	Webservice	
Client	
		
HTTP	
GET	
/student/78/scores	
{	id:	78,	maths	:	89,	physics:81	}	
Server
REST	
•  Introduced	by	Roy	Fielding,	2000	
•  REpresentaMonal	State	Transfer	
– Use	HTTP	methods	explicitly.	
•  POST,	GET,	PUT,	DELETE	
– Be	stateless.	
– Expose	directory	structure-like	URIs.	
•  h1p://www.myservice.org/discussion/topics/{topic}	
– Transfer	XML,	JSON	or	both
Why	REST	
•  Why	REST	
– Minimize	coupling	between	client	and	server	
– Client	becomes	resilient	to	server	changes	
•  Why	Not	REST	
– Secure	data	should	not	be	sent	as	URI
Stateful	design	
Client	
Web	
Service	
previousPage++	
nextPage	=	previousPage	
return	nextPage	
	
GET	/book/next_page		
JSON	response
Stateless	design	
Client	
Web	
Service	
getPage(2)	
	
GET	/book/page/2		
JSON	response
Go	advantage	
•  Deployment		
– Single	binary	
– Dependency	needs	staMc	Mme	managing	
•  Performance	of	go	
– Built-in	concurrency	
•  Garbage	collecMon
Basic	web	service	using	FileIO	
•  The	service	handles	inventory	of	IPAddresses		
•  Uses	
– net/h1p	of	for	handling	h1p	request	
•  h1p.ListenAndServe()	
– Handles	concurrent	requests	
– gorrilla/mux	for	parameterized	rouMng	
– os	and	bufio	for	file	handling	
•  h1ps://github.com/u1amgandhi24/ipalloc
Let’s	build	this	webservice….
Adding	Handlers
Handler	for	Get	Request
Handler	for	Post	request
IPAlloc	In	AcMon	
•  ipalloc	
•  ipalloc	service	listening	on	8123	….	
•  curl	–XPOST	–d	
’{“Name”:”dev8”,”IPAddress”:”1.2.3.12”}’	
h1p://localhost:8123/ipalloc	
•  curl	–G	h1p://localhost:8123/ipalloc/1.2.3.12	
				{“Name”:”device12”,”IPAddress”:”1.2.3.12”}
TesMng	
•  test	and	h1ptest	
•  Write	tests	in	_test.go	files	
•  func	TestMain	to	write	setup	and	tear-down	
code	
•  Test	case	should	start	with	Test	prefix	
•  go	test	runs	all	tests	
•  go	test	–cover	runs	the	test	and	shows	
coverage
Test	An	API
Securing	with	JWT.io	
•  Json	web	tokens	
–  JSON	Web	Token	(JWT)	is	an	open	standard	(RFC	7519)	
that	defines	a	compact	and	self-contained	way	for	securely	
transminng	informaMon	between	parMes	as	a	JSON	
object.	
•  Library	support	
–  C,	Go,	Swip,	Scala,	.NET,	Java,	Python,	Node.js	…...	
•  Structure	of	JWT	
–  base64	encoded	header	
–  base64	encoded	payload	
–  signature	of	the	dot	separated	header	and	payload.	
•  h1ps://github.com/u1amgandhi24/jwtdemo
Client	 Web	Service	
POST	/auth	
User=..		Password=…	
HTTP	200	OK	
{		JWT	Token..	}	
GET	/book/page/2	
Auth:	JWT	Token	
HTTP	200	OK	
{		Page	2	}	
Validate	
JWT
Generate	JWT	in	go
Parse	JWT	Token	in	go
JWT	In	AcMon	
•  jwtdemo	
•  jwtdemo	service	listening	on	3080	….	
•  curl	–XPOST	–H	“AuthenMcaMon	:	
U3luZXJ6aXAxOlBhc3N3b3JkMQ==”	h1ps://localhost:3080/
authenMcate	
•  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0NTU2MTQzOT
Z9.pzRgQSRHwSfUymQPsG-LVaH_2n10g3wxpJltYuiUco0"	
•  curl	–H	“AuthenMcaMon	:	
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0NTU2MTQzOTZ
9.pzRgQSRHwSfUymQPsG-LVaH_2n10g3wxpJltYuiUco0”	h1p://
localhost:3080/book/page/2				
					{"PageNum":2,	"content":"This	a	sample	page”}
HosMng	
•  Heroku	
– Signup	and	install	toolbelt	
– Create	go	webapp		
– Godep	(	dependency	manager	)	
– Push	to	heroku	
•  h1ps://mmcgrana.github.io/2012/09/genng-
started-with-go-on-heroku.html
Thank	You	
QuesMons
References	
•  h1p://thenewstack.io/make-a-resxul-json-api-go/	
•  h1p://www.ibm.com/developerworks/library/ws-
resxul/	
•  h1ps://scotch.io/tutorials/the-ins-and-outs-of-token-
based-authenMcaMon	
•  h1p://jwt.io/	
•  h1p://dghubble.com/blog/posts/json-web-tokens-
and-go/	
•  h1p://www.tutorialized.com/tutorial/RESTful-Web-
services:-The-basics/40001
References	
•  h1ps://golang.org/pkg/encoding/base64/
#example_Encoding_DecodeString	
•  h1p://stackoverflow.com/quesMons/
1368014/why-do-we-need-resxul-web-
services	
•  h1p://di-side.com/di-side/services/web-
soluMons/rest-webservice-symfony/	
•  h1p://spf13.com/post/soap-vs-rest

More Related Content

PDF
Writing HTTP Middleware In Go
PDF
Building & Testing Scalable Rails Applications
PPTX
Melbourne User Group OAK and MongoDB
PPTX
MongoDB and MongoMK Source Event
PPTX
Rest assured
PDF
Progressive Web Apps
PPTX
ASP.NET Mvc 4 web api
PPTX
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
Writing HTTP Middleware In Go
Building & Testing Scalable Rails Applications
Melbourne User Group OAK and MongoDB
MongoDB and MongoMK Source Event
Rest assured
Progressive Web Apps
ASP.NET Mvc 4 web api
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...

What's hot (20)

PPTX
Getting Started with Web Services
PPTX
Debugging Microservices - key challenges and techniques - Microservices Odesa...
PDF
Microsoft exchange
PPTX
Building solutions with the SharePoint Framework - deep-dive
PPTX
Node Session - 3
PPTX
Web services - A Practical Approach
PPTX
WSO2 Gateway
PPTX
ASP.NET WEB API Training
PPTX
Advance java session 2
PPTX
An Overview of Web Services: SOAP and REST
PDF
ASP.NET Scalability - VBUG London
PPTX
Building Modern Web Applications with ASP.NET5
PDF
Nginx caching
PDF
Enterprise WordPress - Performance, Scalability and Redundancy
PPSX
Welcome to Web Services
PPT
Web servers (l6)
PPTX
Using the Cascade Server Web Service API, by Artur Tomusiak
PPTX
Signal rity1
PDF
Web Performance Part 3 "Server-side tips"
PDF
Optimising for Performance
Getting Started with Web Services
Debugging Microservices - key challenges and techniques - Microservices Odesa...
Microsoft exchange
Building solutions with the SharePoint Framework - deep-dive
Node Session - 3
Web services - A Practical Approach
WSO2 Gateway
ASP.NET WEB API Training
Advance java session 2
An Overview of Web Services: SOAP and REST
ASP.NET Scalability - VBUG London
Building Modern Web Applications with ASP.NET5
Nginx caching
Enterprise WordPress - Performance, Scalability and Redundancy
Welcome to Web Services
Web servers (l6)
Using the Cascade Server Web Service API, by Artur Tomusiak
Signal rity1
Web Performance Part 3 "Server-side tips"
Optimising for Performance
Ad

Similar to Webservices ingo (20)

PDF
Creating Restful Web Services with restish
PPTX
Rest webservice ppt
PPTX
REST Presentation
PPTX
RESTful Web Services
ODP
The Internet as Web Services: introduction to ReST
PPTX
Restful webservice
PDF
What are restful web services?
PDF
Understanding Web services
PDF
REST APIS web development for backend familiarity
PPTX
Mini-Training: Let's have a rest
PPT
ROA.ppt
PPTX
rest-api-basics.pptx
PPTX
REST & RESTful Web Services
PDF
Introduction to Restful Web Services
PDF
Securty Testing For RESTful Applications
PPTX
Party + REST = Win
PDF
PPTX
RESTful_Web_Services_Presentation (1).pptx
PDF
wsadddddddddddddddddeb-servsdddddddddddaaaaaaaice.pdf
PPTX
Microservices in go
Creating Restful Web Services with restish
Rest webservice ppt
REST Presentation
RESTful Web Services
The Internet as Web Services: introduction to ReST
Restful webservice
What are restful web services?
Understanding Web services
REST APIS web development for backend familiarity
Mini-Training: Let's have a rest
ROA.ppt
rest-api-basics.pptx
REST & RESTful Web Services
Introduction to Restful Web Services
Securty Testing For RESTful Applications
Party + REST = Win
RESTful_Web_Services_Presentation (1).pptx
wsadddddddddddddddddeb-servsdddddddddddaaaaaaaice.pdf
Microservices in go
Ad

Recently uploaded (20)

PPTX
Introduction to Information and Communication Technology
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPT
tcp ip networks nd ip layering assotred slides
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
The Internet -By the Numbers, Sri Lanka Edition
DOCX
Unit-3 cyber security network security of internet system
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
innovation process that make everything different.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
Introduction to Information and Communication Technology
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Decoding a Decade: 10 Years of Applied CTI Discipline
tcp ip networks nd ip layering assotred slides
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
INTERNET------BASICS-------UPDATED PPT PRESENTATION
522797556-Unit-2-Temperature-measurement-1-1.pptx
The Internet -By the Numbers, Sri Lanka Edition
Unit-3 cyber security network security of internet system
Sims 4 Historia para lo sims 4 para jugar
international classification of diseases ICD-10 review PPT.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
An introduction to the IFRS (ISSB) Stndards.pdf
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
innovation process that make everything different.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf

Webservices ingo