-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20_api.slide
219 lines (137 loc) · 5.41 KB
/
20_api.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
# API
Application Programming Interface
## what is API
API stands for application programming interface, which is a set of definitions and protocols for building and integrating application software.
_source: https://www.redhat.com/en/topics/api/what-are-application-programming-interfaces_
## client server architecture
## client server architecture
**basic client server architecture**
.image _concepts/20_api/Client-server-model.png _ 400
_source: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Client-server-model.svg/1200px-Client-server-model.svg.png_
## client server architecture
**request - response model**
.image _concepts/20_api/client-server-request-response.png _ 400
_source: https://darvishdarab.github.io/cs421_f20/assets/images/client-server-1-d85a93ea16590c10bed340dd78294d0d.png_
: more TODO: to add
: 1. https://intellipaat.com/blog/wp-content/uploads/2021/09/image-99.png
: 2. https://darvishdarab.github.io/cs421_f20/docs/readings/client_server/
## client server architecture
.video _concepts/20_api/request-flow/restful_api_request_flow.mp4 video/mp4 500 _
## RESTful API standard
## RESTful API standard
**intro**
Representational state transfer (REST) is a software architectural style that describes the architecture of the Web.
_source: https://en.m.wikipedia.org/wiki/Representational_state_transfer_
## RESTful API standard
**characteristics of REST**
https://www.scrapingbee.com/blog/six-characteristics-of-rest-api/
## RESTful API standard
**anatomy of API request and response**
TODO: need to find a diagram or make one
: show these parts using postman
////////////////////////////////////////////////////////////////////////
## RESTful API standard: request
## RESTful API standard
**request anatomy**
- method
- path: url/uri/resource
- request body
- headers
## RESTful API standard
**request: method**
indicates the type of the request operation: CRUD (Create Read Update Delete) operations and more
- POST: creating a new resource
- GET: get details of an existing resource
- DELETE: deleting an existing resource
- PUT: updating an existing resource, updates the complete record (all fields)
- PATCH: updating an existing resource, by passing only the fields to be updated
- and more uncommon methods
## sql vs rest
// TODO: compare these methods with CRUD
// SQL vs REST
// table resource
// INSERT POST
// SELECT GET
// DELETE DELETE
// UPDATE PUT/PATCH
## RESTful API standard
**request: method**
Idempotent REST APIs
https://restfulapi.net/idempotent-rest-apis/
## RESTful API standard
**request: path**
path includes uri (universal resource identifier)
example: in www.example.com/api/student/123
- "/api" is the optional prefix to indicate that this is a API URL
- "/student" identifies the resource and is called the URI (in general)
- "/123" id
// TODO: (at a later slide) add examples of how path will be for different methods
## RESTful API standard
**request: body**
data associated with the request
example (json):
{"name":"rohit","addr":"","marks":300}
: data can be of any format (example, json, plain text, html, etc) as long as the client and server agrees upon
: .
: server can also accept data in multiple formats, in which case client should indicate the data type using the content-type header.
## RESTful API standard
**request: headers**
key value pairs used to store
- metadata
- user authentication
- and more
example:
Content-type: application/json
- there are many common headers (like above),
- the server and client can define their own headers, as long as they both understand the purpose of it.
////////////////////////////////////////////////////////////////////////
## RESTful API standard: response
## RESTful API standard
**response anatomy**
- status code
- response body
- headers
## RESTful API standard
**response: status code**
numerical code indicating the status of the request process
- 2xx: success
- 4xx: client side error
- 5xx: server side error
.link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status and more
## RESTful API standard
**response: body**
response data sent to the client by the server
example (json):
{"name":"rohit","addr":"","marks":300}
: data can be of any format (example, json, plain text, html, etc) as long as the client and server agrees upon
## RESTful API standard
**response: headers**
key value pairs used to store
- metadata
- user authentication
- and more
example:
Content-type: application/json
Content-type: application/xml
## RESTful API standard
**further read**
.link https://blog.uptrends.com/technology/the-anatomy-of-an-api-call/ The anatomy of an API call
.link https://www.geeksforgeeks.org/rest-api-introduction/
.link https://www.youtube.com/watch?v=7YcW25PHnAA Video: REST API concepts and examples
.link https://www.youtube.com/watch?v=lsMQRaeKNDk Video: What is a REST API?
////////////////////////////////////////////////////////////////////////
## api designing using swagger
## api designing using swagger
**what is swagger**
## api designing using swagger
**swagger editor**
https://editor.swagger.io/
## api designing using swagger
**example**
////////////////////////////////////////////////////////////////////////
## api server programming using net/http package
1helloworld.go
2server.go
## api server programming using gorilla mux package
## api server programming using other 3rd party packages
## api client programming using net/http package