-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi-spec.yaml
More file actions
233 lines (233 loc) · 7.12 KB
/
api-spec.yaml
File metadata and controls
233 lines (233 loc) · 7.12 KB
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
openapi: 3.0.3
info:
title: Rails Url Shortener
description: A small application for making short urls
contact:
email: short@truggeri.com
license:
name: MIT
url: https://github.com/truggeri/rails-url-shortener/blob/main/LICENSE
version: 1.2.0
servers:
- url: https://short.truggeri.com/
externalDocs:
description: See our Github
url: https://github.com/truggeri/rails-url-shortener/
tags:
- name: use
description: Using a short URL
- name: management
description: Routes for managing URL shorts
- name: ops
description: Routes used for the operation of the app
paths:
/:
post:
tags:
- management
summary: Create a new short URL
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
required:
- full_url
type: object
properties:
full_url:
description: The target URL. Must be between 3 and 500 characters.
example: https://petfinder.com
type: string
short_url:
description: The desired short URL. Only alpha numeric and - _ characters allowed. Must be between 4 and 100 characters. All characters (a-z) are lower cased
example: doggo
type: string
responses:
200:
description: The short URL was successfully created
content:
application/json:
schema:
required:
- cost
- created_at
- full_url
- short_url
- token
type: object
properties:
cost:
type: number
description: The cost of the short in USD
example: 9
created_at:
type: string
description: Date in iso8601 format
example: "2021-06-23T13:46:18+00:00"
full_url:
type: string
description: Full url given
example: https://petfinder.com
short_url:
type: string
description: The short url given
example: doggo
token:
type: string
description: A jwt token used for authorizing the removal of this short
example: jwen.dfho.efoisn
400:
description: The provided params are not valid
content:
application/json:
schema:
required:
- errors
- message
type: object
properties:
errors:
type: array
description: Array of error messages
example: ["Short url only alpha numeric and - _ allowed"]
message:
type: string
description: Bad request
example: Bad request
401:
description: The provided authentication is not authorized to remove this short URL
/{short_url}:
get:
tags:
- use
summary: Short URL
description: A request with a short URL.
parameters:
- name: short_url
in: path
description: The short URL code
required: true
schema:
type: string
responses:
302:
description: Redirect to the full URL
headers:
Location:
schema:
type: string
description: The full URL
404:
description: Short URL could not be found
delete:
tags:
- management
summary: Delete a short URL
description: Remove a short URL from use. Authorization is required from the creation of the token.
parameters:
- name: short_url
in: path
description: The short URL code
required: true
schema:
type: string
- in: header
name: Authorization
schema:
type: string
format: bearer token
required: true
example: bearer jwen.dfho.efoisn
responses:
200:
description: The short URL was successfully removed
401:
description: The provided bearer is not authorized to remove this short URL
404:
description: Short URL could not be found
/count:
get:
tags:
- ops
summary: Gives a count of the number of shorts in the system
description: Gives the total number of shorts in the system
responses:
200:
description: The count of shorts
content:
application/json:
schema:
required:
- count
type: object
properties:
count:
type: number
description: The number of shorts
example: 5
/suggestion:
post:
tags:
- management
summary: Gives a suggested short_url based on a full_url
description: Given a full_url in parameters, we can provide a short_url with minimal cost
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
required:
- full_url
type: object
properties:
full_url:
description: The target URL.
example: https://petfinder.com
type: string
responses:
200:
description: Valid short_url suggestion
content:
application/json:
schema:
required:
- hostname
- short
type: object
properties:
hostname:
type: string
description: The derived hostname that was used for the suggestion
example: petfinder
short:
type: string
description: The suggested short_url
example: ptfn
400:
description: Given full_url is invalid and we cannot suggest
content:
application/json:
schema:
required:
- errors
- message
type: object
properties:
errors:
type: string
description: Description of what's wrong
example: given hostname is invalid
message:
type: string
description: Bad request
example: Bad request
/health:
get:
tags:
- ops
summary: Health check
description: Simple route used to ensure the app is alive
responses:
200:
description: Healthy