-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestful.slide
276 lines (141 loc) · 6.44 KB
/
restful.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
Do zero ao deploy
Receiving files in an api REST
Tags: go, rest, uploads files, api gateway, aws, amazon
Jefferson Otoni Lima
*CEO* & *Co-Fundador* | S3wf & S3commerce entrepreneur 2007
*Full-Stack* *programmer*
* Alguns projetos atuais que participo!
- Web service REST para Uploads e Downloads
- Web service REST para ser consumido
- Microserviços
- Integrações com Mercado Livre / Moip / Correio / JadLog / B2W
- Integrações com Amazon / S3 / EFS / API Gatewy / SES /SQS
.image images2/golang4.png
* Recebendo arquivos em uma api REST !
Cronstruindo um restful para ser consumido ...
.image images2/images12.png
* Criação do servidor REST
- Qual Gateway ou Proxy Reverse usar ?
- Qual arquitetura implementar ?
- Como vamos Escalar ?
- Qual linguagem/Framework usar ?
- Vamos fazer decomposição do sistema ?
.image images2/golang2.png
* API Layers, Gateways, Proxy e SSL
- [[https://console.aws.amazon.com/apigateway][Api Gateway]] (_Amazon_)
- [[https://docs.microsoft.com/en-us/azure/api-management/][Azure]] (_Microsoft_)
- [[https://www.dreamfactory.com/][Dreamfactory]] (_Dreamfactory_)
- [[https://firebase.google.com/docs/database/rest/start?hl=pt-br][Firebase]] (_Google_)
- [[https://getkong.org/][kong]] (_Gerenciador_ _de_ _APIs_ _e_ _Microserviços_ _open_-_source_)
- [[https://traefik.io/][traefik]] (_HTTP_ _reverse_ _proxy_ _and_ _load_ _balancer_)
- [[https://letsencrypt.org/getting-started][letsencrypt]] (_SSL_ _letsencrypt_ _free_)
.image images/go-aviator.png 600 600
* Nossa arquitetura com Gateway
.image images2/api-gateway3.png 490 800
* Nossa arquitetura com Proxy Reverse
.image images2/architecture.png 500 900
* Escalando nosso web service
- AWS Elastic Beanstalk
- AWS Elastic Load Balancing
.image images2/scale.png
* Antes vamos contextualizar
alguns conceitos importantes !
.image images2/golang7.jpg
* O que é REST ?
- [[https://pt.wikipedia.org/wiki/REST][*REST*]] (Representational State Transfer)
- É uma *abstração* da *arquitetura* da World Wide Web [pattern]
- *2000* por [[https://en.wikipedia.org/wiki/Roy_Fielding][Roy Fielding]]
- [[https://pt.wikipedia.org/wiki/Chamada_de_procedimento_remoto][RPC]] não é um exemplo de REST {[[http://go-talks.appspot.com/github.com/gobelohorizonte/gotalks/server-rest.slide][Apresentação Socket / RPC]]}
- RESTful (_São_ _as_ _aplicações_ _ou_ _sistemas_ _que_ _usam_ _princípio_ _REST_)
.image images/go-aviator.png 600 600
* Concepções REST
- Resources => /insert, /update, /delete, /search [URI]
- Representation => Html, Json, Xml, ... / Content-Type
- State Transfer => GET, POST, PUT, DELETE ...
.image images/go-aviator.png 600 600
* Como funciona o protocolo HTTP ?
- [[https://pt.wikipedia.org/wiki/Hypertext_Transfer_Protocol][Hypertext Transfer Protocol]]
- Mensagem HTTP [[https://pt.wikipedia.org/wiki/Lista_de_c%C3%B3digos_de_estado_HTTP][códigos http]]
- Cabeçalho da mensagem [[https://tools.ietf.org/html/rfc2616][*RFC* *2616*]]
- Corpo da mensagem
- Requisição (Request-Line,Request-header,Method, URI e HTTP-Version)
- Métodos (GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS e CONNECT)
.image images/go-aviator.png 600 600
* Clientes REST
- [[https://ec.haxx.se][cURL (_criar_ _requisições_ _em_ _diversos_ _protocolos_)]]
- [[https://www.getpostman.com/][Postman]]
- [[https://httpie.org/][HTTPie]]
- [[https://www.hurl.it/][Hurl.it]]
.image images/go-aviator.png 600 600
* Frameworks REST
- [[https://github.com/avelino/awesome-go/blob/master/README.md][awesome-go]] (_links_ _diversos_)
- [[https://github.com/sogko/slumber][Slumer]] (_API_ _REST_)
- [[https://github.com/gorilla/mux][Mux]] (_simples_ _roteador_ _url_)
- [[https://github.com/julienschmidt/httprouter][HttpRouter]] (_poderoso_ _roteador_ _url_)
- [[https://github.com/verdverm/frisby][Frisby]] (_REST_ _API_ _TEST_)
- [[https://github.com/pressly/chi][Pressly chi]] (_Http_ _Service_ _REST_)
- [[https://github.com/rs/formjson][Go JSON handler]]
- [[https://github.com/alioygur/gores][gores]] (_handles_ _HTML_, _JSON_, _XML_)
.image images/golang1.png
* Opa.. Golang now, vamos implementar!
.image images/golang1.png
* Construindo nosso server REST / ListenAndServe ( )
// http
//
http.ListenAndServe(":9999", nil)
// servindo um site estático
//
http.ListenAndServe(":9999", http.FileServer(http.Dir("/static/site"))))
// ssl
//
http.ListenAndServeTLS(":443", server.crt, yourkey.key, nil)
// Criando chaves ssl
//
~/user-linux$ openssl req -nodes -newkey rsa:2048 -keyout yourkey.key -out serve.csr
.image images2/golang6.jpg
* Definindo Rotas Handlers!
* Server httpRouter {Criando rotas}
.code -edit httprouter/rest-httprouter-server.go /^func main/,/^}/
* Rotas e Tipos de Uploads
.code -edit mux/server-mux-upload.go /^func main/,/^}/
* Subindo varias portas com ListenAndServe()
.code -edit mux/server-mux-upload.go /^func listenAndServer/,/^}/
* Copy para servidor único arquivio
.code -edit mux/server-mux-upload.go /^func uploadFormFile/,/^}/
* Copy para servidor multipolos arquivos
.code -edit mux/server-mux-upload.go /^func uploadFormFileMulti/,/^}/
* Uploads Binary
.code -edit mux/server-mux-upload.go /^func uploadBinary/,/^}/
.image images2/golang4.png
* cURL testando nosso REST
* Upload Form / multipart/form-data
curl -i -X POST http://localhost:9999/upload-form \
-u "API_KEY:383883jef903xxxx838xxxx" \
--form "fileupload=@files/file2.pdf"
.image images2/golang7.png
* Upload Form multi / multipart/form-data
curl -i --request POST localhost:9999/upload-form-multi \
-u "API_KEY:383883jef903xxxx838xxxx" \
--form 'email=jefferson&password=3838373773' \
--form "fileupload[]=@files/file1.jpg" \
--form "fileupload[]=@files/file2.pdf"
.image images2/images11.png
* Upload Binary
// http://https://xxxxxx.execute-api.us-xxx-x.amazonaws.com/upload-bin \
curl -i --request POST http://localhost:9999/upload-bin \
-u "API_KEY:383883jef903xxxx838xxxx" \
-H "Accept: binary/octet-stream" \
-H "Content-Type: binary/octet-stream" \
-H "Name-File: file2.pdf" \
--data-binary "@files/file2.pdf"
.image images2/golang1.jpg
* Referências
.link https://github.com/avelino/awesome-go/blob/master/README.md
.link https://golang.org/pkg/net
.link https://godoc.org/golang.org/x/net/websocket
.link https://golang.org/pkg/net/rpc
.link https://github.com/gorilla/mux
.link https://github.com/fiorix/wsdl2go
.link https://github.com/julienschmidt/httprouter
* Dúvidas?
.image images/help.png