SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
RESTful API Development using Go
Baiju Muthukadan
@nogenerics
Baiju Muthukadan RESTful API Development using Go @nogenerics 1 / 30
Baiju Muthukadan RESTful API Development using Go @nogenerics 2 / 30
About Me
Senior Software Engineer, Red Hat
1
https://golang.muthukadan.net
Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
About Me
Senior Software Engineer, Red Hat
FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.)
1
https://golang.muthukadan.net
Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
About Me
Senior Software Engineer, Red Hat
FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.)
Founded the Swathanthra Malayalam Computing (SMC) project in 2001
while studying at REC Calicut (NIT Kozhikode)
1
https://golang.muthukadan.net
Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
About Me
Senior Software Engineer, Red Hat
FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.)
Founded the Swathanthra Malayalam Computing (SMC) project in 2001
while studying at REC Calicut (NIT Kozhikode)
Received the first Kenneth Gonsalves Award for contributions to the
Python community in India
1
https://golang.muthukadan.net
Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
About Me
Senior Software Engineer, Red Hat
FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.)
Founded the Swathanthra Malayalam Computing (SMC) project in 2001
while studying at REC Calicut (NIT Kozhikode)
Received the first Kenneth Gonsalves Award for contributions to the
Python community in India
Author of the book: A Comprehensive Guide to Go Programming 1
1
https://golang.muthukadan.net
Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
Quick introduction to Go
General Purpose Programming Language
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Object Oriented (Composition over inheritance no classes!)
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Object Oriented (Composition over inheritance no classes!)
Compiled (Statically linked)
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Object Oriented (Composition over inheritance no classes!)
Compiled (Statically linked)
Garbage collected
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Object Oriented (Composition over inheritance no classes!)
Compiled (Statically linked)
Garbage collected
Statically typed
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go
General Purpose Programming Language
Free/Open Source
Created at Google by Robert Griesemer, Rob Pike and Ken Thompson
Development started in 2007 and publicly released in November 2009
C like syntax (no semicolons)
Object Oriented (Composition over inheritance no classes!)
Compiled (Statically linked)
Garbage collected
Statically typed
Strongly typed
Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
Quick introduction to Go ...
built-in concurrency
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
CPU Architectures: amd64, 386, arm etc.
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
CPU Architectures: amd64, 386, arm etc.
Cross compilation
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
CPU Architectures: amd64, 386, arm etc.
Cross compilation
Standard library
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
CPU Architectures: amd64, 386, arm etc.
Cross compilation
Standard library
No exceptions (Errors are values)
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Quick introduction to Go ...
built-in concurrency
Two major compilers: gc & gccgo
25 keywords (less than C,C++,Python etc.)
Classification (Capitalized are exported public)
Fast build (in seconds)
Unused imports and variables raise compile error
Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc.
CPU Architectures: amd64, 386, arm etc.
Cross compilation
Standard library
No exceptions (Errors are values)
Pointers (No pointer arithmetic!)
Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
Basic example
package main
import "net/http"
func main() {
http.ListenAndServe(":8080", nil)
}
Baiju Muthukadan RESTful API Development using Go @nogenerics 6 / 30
Serve content example
package main
import "net/http"
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
}
func main() {
http.HandleFunc("/", homeHandler)
http.ListenAndServe(":8080", nil)
}
Baiju Muthukadan RESTful API Development using Go @nogenerics 7 / 30
Gorilla Mux
URL router and dispatcher
http://www.gorillatoolkit.org/pkg/mux
https://github.com/gorilla/mux
go get -u github.com/gorilla/mux
Baiju Muthukadan RESTful API Development using Go @nogenerics 8 / 30
Gorilla Mux Example
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!n"))
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/", homeHandler).Methods("GET")
http.Handle("/", r)
http.ListenAndServe(":8080", nil)
}
Baiju Muthukadan RESTful API Development using Go @nogenerics 9 / 30
Negroni Example
func main() {
r := mux.NewRouter()
r.HandleFunc("/", homeHandler)
n := negroni.New()
n.UseHandler(r)
http.ListenAndServe(":8080", n)
}
Baiju Muthukadan RESTful API Development using Go @nogenerics 10 / 30
Negroni Middleware
An exaple from
https://github.com/kaaryasthan/kaaryasthan/blob/master/route/route.go
n = negroni.New(negroni.NewRecovery(),
negroni.NewLogger(),
negroni.NewStatic(web.AssetFS()))
n.Use(middleware)
Middlewares: gzip, jwt, cors, csp
Baiju Muthukadan RESTful API Development using Go @nogenerics 11 / 30
Paths with variable
r := mux.NewRouter()
r.HandleFunc("/products/{key}", ProductHandler)
r.HandleFunc("/articles/{category}/", ArticlesCategoryHandler)
r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler)
Format: {name} or {name:pattern}
Baiju Muthukadan RESTful API Development using Go @nogenerics 12 / 30
Frameworks
https://gobuffalo.io
https://goa.design
https://gin-gonic.github.io/gin
https://beego.me
https://awesome-go.com/#web-frameworks
Baiju Muthukadan RESTful API Development using Go @nogenerics 13 / 30
RESTful
stateless
unique identification of resources through URIs
standard HTTP methods (POST, GET, PATCH, DELETE)
HTTP status codes
Baiju Muthukadan RESTful API Development using Go @nogenerics 14 / 30
Why RESTful?
easy to understand & document
works on limited bandwidth
READs can be cached and hence reduces the bandwidth
Baiju Muthukadan RESTful API Development using Go @nogenerics 15 / 30
Architecture constraints
uniform interface
client-server
stateless
Cache-able
Layered system
Baiju Muthukadan RESTful API Development using Go @nogenerics 16 / 30
REST Style consists of ...
Resources
Verbs
Media types
Status codes
Baiju Muthukadan RESTful API Development using Go @nogenerics 17 / 30
Media types
Use JSON ( http://json.org )
or better JSON API SPEC ( http://jsonapi.org )
application/vnd.api+json
Baiju Muthukadan RESTful API Development using Go @nogenerics 18 / 30
Authentication
Use JWT: https://jwt.io
Baiju Muthukadan RESTful API Development using Go @nogenerics 19 / 30
Security
All attacks possible with web are applicable to REST API.
https://www.owasp.org
- Use TLS always
Baiju Muthukadan RESTful API Development using Go @nogenerics 20 / 30
Tooling
cURL is your friend!
Baiju Muthukadan RESTful API Development using Go @nogenerics 21 / 30
HTTP Methods
POST - Create
GET - Read
PATCH - Update
DELETE - Delete
Baiju Muthukadan RESTful API Development using Go @nogenerics 22 / 30
An example API end points
Create item - POST /items
Read a single item - GET /items/1
Read all items - GET /items
Update item - PATCH /items/1
Delete item - DELETE /items/1
Baiju Muthukadan RESTful API Development using Go @nogenerics 23 / 30
API versioning
/api/v1/items
/api/v2/items
Baiju Muthukadan RESTful API Development using Go @nogenerics 24 / 30
jsonapi.org
standard for representation of JSON responses
shared convention increase productivity through generalized tooling
Baiju Muthukadan RESTful API Development using Go @nogenerics 25 / 30
resource representation in JSON
{
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page[offset]=2",
"last": "http://example.com/articles?page[offset]=10"
},
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
...
Baiju Muthukadan RESTful API Development using Go @nogenerics 26 / 30
HTTP Status codes and Location header
If a POST request did not include a Client-Generated ID and the requested
resource has been created successfully, the server MUST return a 201
Created status code.
The response SHOULD include a Location header identifying the location of
the newly created resource.
Baiju Muthukadan RESTful API Development using Go @nogenerics 27 / 30
structure for errors
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/vnd.api+json
{
"errors": [
{
"status": "422",
"source": { "pointer": "/data/attributes/first-name" },
"title": "Invalid Attribute",
"detail": "First name must contain at least three characters."
}
]
}
Baiju Muthukadan RESTful API Development using Go @nogenerics 28 / 30
Conclusion
Go is a great choice for RESTful API development
Baiju Muthukadan RESTful API Development using Go @nogenerics 29 / 30
Thank You!
@nogenerics
Baiju Muthukadan RESTful API Development using Go @nogenerics 30 / 30

Más contenido relacionado

La actualidad más candente

Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangErhan Yakut
 
Rib Console and plugins to make you happier
Rib Console and plugins to make you happierRib Console and plugins to make you happier
Rib Console and plugins to make you happierM C
 
Coding with golang
Coding with golangCoding with golang
Coding with golangHannahMoss14
 
JAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled JavaJAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled Javajazoon13
 
Opencast Architecture
Opencast ArchitectureOpencast Architecture
Opencast ArchitectureGregLogan7
 
How To Use The Codename One Sources
How To Use The Codename One SourcesHow To Use The Codename One Sources
How To Use The Codename One SourcesShai Almog
 
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...mCloud
 
Porting golang development environment developed with golang
Porting golang development environment developed with golangPorting golang development environment developed with golang
Porting golang development environment developed with golangSeongJae Park
 
Nextcloud Android App Development Process Insights
Nextcloud Android App Development Process InsightsNextcloud Android App Development Process Insights
Nextcloud Android App Development Process InsightsAndy Scherzinger
 
Android Study Jam - Info Session
Android Study Jam - Info SessionAndroid Study Jam - Info Session
Android Study Jam - Info SessionDSCVSSUT
 
Software development made serious
Software development made seriousSoftware development made serious
Software development made seriousDanilo Pianini
 
It's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolboxIt's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolboxStefan Lay
 
Golang skills pre-session
Golang skills pre-sessionGolang skills pre-session
Golang skills pre-sessionsofianinho
 
ReviewNinja OSCON
ReviewNinja OSCONReviewNinja OSCON
ReviewNinja OSCONdfarr219
 
Mobile Backend Development with Ktor
Mobile Backend Development with KtorMobile Backend Development with Ktor
Mobile Backend Development with KtorSina Rezaei
 
Refactoring to GO modules
Refactoring to GO modulesRefactoring to GO modules
Refactoring to GO modulesElad Hirsch
 

La actualidad más candente (20)

Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with Golang
 
Rib Console and plugins to make you happier
Rib Console and plugins to make you happierRib Console and plugins to make you happier
Rib Console and plugins to make you happier
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
 
JAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled JavaJAZOON'13 - Andres Almiray - Rocket Propelled Java
JAZOON'13 - Andres Almiray - Rocket Propelled Java
 
Opencast Architecture
Opencast ArchitectureOpencast Architecture
Opencast Architecture
 
How To Use The Codename One Sources
How To Use The Codename One SourcesHow To Use The Codename One Sources
How To Use The Codename One Sources
 
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
 
Intro to Git & GitHub
Intro to Git & GitHubIntro to Git & GitHub
Intro to Git & GitHub
 
Porting golang development environment developed with golang
Porting golang development environment developed with golangPorting golang development environment developed with golang
Porting golang development environment developed with golang
 
Driving development in PHP
Driving development in PHPDriving development in PHP
Driving development in PHP
 
Nextcloud Android App Development Process Insights
Nextcloud Android App Development Process InsightsNextcloud Android App Development Process Insights
Nextcloud Android App Development Process Insights
 
Android Study Jam - Info Session
Android Study Jam - Info SessionAndroid Study Jam - Info Session
Android Study Jam - Info Session
 
Software development made serious
Software development made seriousSoftware development made serious
Software development made serious
 
It's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolboxIt's all about feedback - code review as a great tool in the agile toolbox
It's all about feedback - code review as a great tool in the agile toolbox
 
Golang skills pre-session
Golang skills pre-sessionGolang skills pre-session
Golang skills pre-session
 
ReviewNinja OSCON
ReviewNinja OSCONReviewNinja OSCON
ReviewNinja OSCON
 
Mobile Backend Development with Ktor
Mobile Backend Development with KtorMobile Backend Development with Ktor
Mobile Backend Development with Ktor
 
Refactoring to GO modules
Refactoring to GO modulesRefactoring to GO modules
Refactoring to GO modules
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 
How to install and use git
How to install and  use gitHow to install and  use git
How to install and use git
 

Similar a RESTful API Development using Go

Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Codemotion
 
Introduction to git and Github
Introduction to git and GithubIntroduction to git and Github
Introduction to git and GithubWycliff1
 
How I become Go GDE
How I become Go GDEHow I become Go GDE
How I become Go GDEEvan Lin
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to GoSimon Hewitt
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Vadym Kazulkin
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Asher Martin
 
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5Amanda Lam
 
Hacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersHacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersDeepikaRana30
 
Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Derek Jacoby
 
Untangling fall2017 week2
Untangling fall2017 week2Untangling fall2017 week2
Untangling fall2017 week2Derek Jacoby
 
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxorlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxBill Wilder
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Codemotion
 
R1-intro-to-go.pptx
R1-intro-to-go.pptxR1-intro-to-go.pptx
R1-intro-to-go.pptxAbabb2
 
Princeton RSE Peer network first meeting
Princeton RSE Peer network first meetingPrinceton RSE Peer network first meeting
Princeton RSE Peer network first meetingHenry Schreiner
 
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03msohn
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageGanesh Samarthyam
 

Similar a RESTful API Development using Go (20)

Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017
 
Introduction to git and Github
Introduction to git and GithubIntroduction to git and Github
Introduction to git and Github
 
How I become Go GDE
How I become Go GDEHow I become Go GDE
How I become Go GDE
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
 
Hacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersHacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginners
 
Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Untangling fall2017 week2_try2
Untangling fall2017 week2_try2
 
Untangling fall2017 week2
Untangling fall2017 week2Untangling fall2017 week2
Untangling fall2017 week2
 
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxorlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
 
The Awesomeness of Go
The Awesomeness of GoThe Awesomeness of Go
The Awesomeness of Go
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
R1-intro-to-go.pptx
R1-intro-to-go.pptxR1-intro-to-go.pptx
R1-intro-to-go.pptx
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Making shiny shine brighter
Making shiny shine brighterMaking shiny shine brighter
Making shiny shine brighter
 
Versions
VersionsVersions
Versions
 
Princeton RSE Peer network first meeting
Princeton RSE Peer network first meetingPrinceton RSE Peer network first meeting
Princeton RSE Peer network first meeting
 
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 

Último

Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 

Último (20)

Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 

RESTful API Development using Go

  • 1. RESTful API Development using Go Baiju Muthukadan @nogenerics Baiju Muthukadan RESTful API Development using Go @nogenerics 1 / 30
  • 2. Baiju Muthukadan RESTful API Development using Go @nogenerics 2 / 30
  • 3. About Me Senior Software Engineer, Red Hat 1 https://golang.muthukadan.net Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
  • 4. About Me Senior Software Engineer, Red Hat FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.) 1 https://golang.muthukadan.net Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
  • 5. About Me Senior Software Engineer, Red Hat FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.) Founded the Swathanthra Malayalam Computing (SMC) project in 2001 while studying at REC Calicut (NIT Kozhikode) 1 https://golang.muthukadan.net Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
  • 6. About Me Senior Software Engineer, Red Hat FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.) Founded the Swathanthra Malayalam Computing (SMC) project in 2001 while studying at REC Calicut (NIT Kozhikode) Received the first Kenneth Gonsalves Award for contributions to the Python community in India 1 https://golang.muthukadan.net Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
  • 7. About Me Senior Software Engineer, Red Hat FOSS Contributor (SMC, Koha, Zope, SaltStack, fabric8 etc.) Founded the Swathanthra Malayalam Computing (SMC) project in 2001 while studying at REC Calicut (NIT Kozhikode) Received the first Kenneth Gonsalves Award for contributions to the Python community in India Author of the book: A Comprehensive Guide to Go Programming 1 1 https://golang.muthukadan.net Baiju Muthukadan RESTful API Development using Go @nogenerics 3 / 30
  • 8. Quick introduction to Go General Purpose Programming Language Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 9. Quick introduction to Go General Purpose Programming Language Free/Open Source Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 10. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 11. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 12. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 13. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Object Oriented (Composition over inheritance no classes!) Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 14. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Object Oriented (Composition over inheritance no classes!) Compiled (Statically linked) Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 15. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Object Oriented (Composition over inheritance no classes!) Compiled (Statically linked) Garbage collected Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 16. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Object Oriented (Composition over inheritance no classes!) Compiled (Statically linked) Garbage collected Statically typed Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 17. Quick introduction to Go General Purpose Programming Language Free/Open Source Created at Google by Robert Griesemer, Rob Pike and Ken Thompson Development started in 2007 and publicly released in November 2009 C like syntax (no semicolons) Object Oriented (Composition over inheritance no classes!) Compiled (Statically linked) Garbage collected Statically typed Strongly typed Baiju Muthukadan RESTful API Development using Go @nogenerics 4 / 30
  • 18. Quick introduction to Go ... built-in concurrency Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 19. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 20. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 21. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 22. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 23. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 24. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 25. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. CPU Architectures: amd64, 386, arm etc. Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 26. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. CPU Architectures: amd64, 386, arm etc. Cross compilation Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 27. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. CPU Architectures: amd64, 386, arm etc. Cross compilation Standard library Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 28. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. CPU Architectures: amd64, 386, arm etc. Cross compilation Standard library No exceptions (Errors are values) Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 29. Quick introduction to Go ... built-in concurrency Two major compilers: gc & gccgo 25 keywords (less than C,C++,Python etc.) Classification (Capitalized are exported public) Fast build (in seconds) Unused imports and variables raise compile error Operating Systems: Windows, GNU/Linux, Mac OS X, *BSD etc. CPU Architectures: amd64, 386, arm etc. Cross compilation Standard library No exceptions (Errors are values) Pointers (No pointer arithmetic!) Baiju Muthukadan RESTful API Development using Go @nogenerics 5 / 30
  • 30. Basic example package main import "net/http" func main() { http.ListenAndServe(":8080", nil) } Baiju Muthukadan RESTful API Development using Go @nogenerics 6 / 30
  • 31. Serve content example package main import "net/http" func homeHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World!")) } func main() { http.HandleFunc("/", homeHandler) http.ListenAndServe(":8080", nil) } Baiju Muthukadan RESTful API Development using Go @nogenerics 7 / 30
  • 32. Gorilla Mux URL router and dispatcher http://www.gorillatoolkit.org/pkg/mux https://github.com/gorilla/mux go get -u github.com/gorilla/mux Baiju Muthukadan RESTful API Development using Go @nogenerics 8 / 30
  • 33. Gorilla Mux Example package main import ( "net/http" "github.com/gorilla/mux" ) func homeHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World!n")) } func main() { r := mux.NewRouter() r.HandleFunc("/", homeHandler).Methods("GET") http.Handle("/", r) http.ListenAndServe(":8080", nil) } Baiju Muthukadan RESTful API Development using Go @nogenerics 9 / 30
  • 34. Negroni Example func main() { r := mux.NewRouter() r.HandleFunc("/", homeHandler) n := negroni.New() n.UseHandler(r) http.ListenAndServe(":8080", n) } Baiju Muthukadan RESTful API Development using Go @nogenerics 10 / 30
  • 35. Negroni Middleware An exaple from https://github.com/kaaryasthan/kaaryasthan/blob/master/route/route.go n = negroni.New(negroni.NewRecovery(), negroni.NewLogger(), negroni.NewStatic(web.AssetFS())) n.Use(middleware) Middlewares: gzip, jwt, cors, csp Baiju Muthukadan RESTful API Development using Go @nogenerics 11 / 30
  • 36. Paths with variable r := mux.NewRouter() r.HandleFunc("/products/{key}", ProductHandler) r.HandleFunc("/articles/{category}/", ArticlesCategoryHandler) r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler) Format: {name} or {name:pattern} Baiju Muthukadan RESTful API Development using Go @nogenerics 12 / 30
  • 38. RESTful stateless unique identification of resources through URIs standard HTTP methods (POST, GET, PATCH, DELETE) HTTP status codes Baiju Muthukadan RESTful API Development using Go @nogenerics 14 / 30
  • 39. Why RESTful? easy to understand & document works on limited bandwidth READs can be cached and hence reduces the bandwidth Baiju Muthukadan RESTful API Development using Go @nogenerics 15 / 30
  • 40. Architecture constraints uniform interface client-server stateless Cache-able Layered system Baiju Muthukadan RESTful API Development using Go @nogenerics 16 / 30
  • 41. REST Style consists of ... Resources Verbs Media types Status codes Baiju Muthukadan RESTful API Development using Go @nogenerics 17 / 30
  • 42. Media types Use JSON ( http://json.org ) or better JSON API SPEC ( http://jsonapi.org ) application/vnd.api+json Baiju Muthukadan RESTful API Development using Go @nogenerics 18 / 30
  • 43. Authentication Use JWT: https://jwt.io Baiju Muthukadan RESTful API Development using Go @nogenerics 19 / 30
  • 44. Security All attacks possible with web are applicable to REST API. https://www.owasp.org - Use TLS always Baiju Muthukadan RESTful API Development using Go @nogenerics 20 / 30
  • 45. Tooling cURL is your friend! Baiju Muthukadan RESTful API Development using Go @nogenerics 21 / 30
  • 46. HTTP Methods POST - Create GET - Read PATCH - Update DELETE - Delete Baiju Muthukadan RESTful API Development using Go @nogenerics 22 / 30
  • 47. An example API end points Create item - POST /items Read a single item - GET /items/1 Read all items - GET /items Update item - PATCH /items/1 Delete item - DELETE /items/1 Baiju Muthukadan RESTful API Development using Go @nogenerics 23 / 30
  • 48. API versioning /api/v1/items /api/v2/items Baiju Muthukadan RESTful API Development using Go @nogenerics 24 / 30
  • 49. jsonapi.org standard for representation of JSON responses shared convention increase productivity through generalized tooling Baiju Muthukadan RESTful API Development using Go @nogenerics 25 / 30
  • 50. resource representation in JSON { "links": { "self": "http://example.com/articles", "next": "http://example.com/articles?page[offset]=2", "last": "http://example.com/articles?page[offset]=10" }, "data": [{ "type": "articles", "id": "1", "attributes": { "title": "JSON API paints my bikeshed!" }, "relationships": { "author": { "links": { "self": "http://example.com/articles/1/relationships/author", "related": "http://example.com/articles/1/author" }, "data": { "type": "people", "id": "9" } }, ... Baiju Muthukadan RESTful API Development using Go @nogenerics 26 / 30
  • 51. HTTP Status codes and Location header If a POST request did not include a Client-Generated ID and the requested resource has been created successfully, the server MUST return a 201 Created status code. The response SHOULD include a Location header identifying the location of the newly created resource. Baiju Muthukadan RESTful API Development using Go @nogenerics 27 / 30
  • 52. structure for errors HTTP/1.1 422 Unprocessable Entity Content-Type: application/vnd.api+json { "errors": [ { "status": "422", "source": { "pointer": "/data/attributes/first-name" }, "title": "Invalid Attribute", "detail": "First name must contain at least three characters." } ] } Baiju Muthukadan RESTful API Development using Go @nogenerics 28 / 30
  • 53. Conclusion Go is a great choice for RESTful API development Baiju Muthukadan RESTful API Development using Go @nogenerics 29 / 30
  • 54. Thank You! @nogenerics Baiju Muthukadan RESTful API Development using Go @nogenerics 30 / 30