petail 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +75 -10
- data/petail.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417bd45430e7d40be79470dcd1a09f6fbab6ca729a893c02568f944b67592cd5
|
4
|
+
data.tar.gz: 328809222adc5db346e50b7b144a98c3fd4c0f6e32fef701ee03f7d65a33b210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c01be4f0f48a6b5f9b4622b8f133102a8cc0abe073c9176827748b8848f1208c7682590fd52ae0734a696e6cd2fa3d5beb7fc338fc520bc7afaef9cb55eb9a9c
|
7
|
+
data.tar.gz: 1c684b3c8e69e3a9c54b627226e2c3ebdecafe1cf013b70f69ac0c6582a5ff4394e201ece321eee3e1115b7fa8573e7d234edc97e20c5b609a770b05cdcc7fad
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -181,7 +181,7 @@ Both serialization and deserialization of JSON is supported. For example, given
|
|
181
181
|
[source,ruby]
|
182
182
|
----
|
183
183
|
payload = Petail[
|
184
|
-
type: "https://
|
184
|
+
type: "https://demo.io/problem_details/out_of_credit",
|
185
185
|
title: "You do not have enough credit.",
|
186
186
|
status: 403,
|
187
187
|
detail: "Your current balance is 30, but that costs 50.",
|
@@ -198,11 +198,11 @@ This means you can serialize as follows:
|
|
198
198
|
[source,ruby]
|
199
199
|
----
|
200
200
|
payload.to_json
|
201
|
-
# "{\"type\":\"https://
|
201
|
+
# "{\"type\":\"https://demo.io/problem_details/out_of_credit\",\"title\":\"You do not have enough credit.\",\"status\":403,\"detail\":\"Your current balance is 30, but that costs 50.\",\"instance\":\"/accounts/1\",\"balance\":30,\"accounts\":[\"/accounts/1\",\"/accounts/10\"]}"
|
202
202
|
|
203
203
|
payload.to_json indent: " ", space: " ", object_nl: "\n", array_nl: "\n"
|
204
204
|
# {
|
205
|
-
# "type": "https://
|
205
|
+
# "type": "https://demo.io/problem_details/out_of_credit",
|
206
206
|
# "title": "You do not have enough credit.",
|
207
207
|
# "status": 403,
|
208
208
|
# "detail": "Your current balance is 30, but that costs 50.",
|
@@ -221,7 +221,7 @@ You can also deserialize by taking the result of the above and turning the raw J
|
|
221
221
|
|
222
222
|
[source,ruby]
|
223
223
|
----
|
224
|
-
Petail.from_json "{\"type\":\"https://
|
224
|
+
Petail.from_json "{\"type\":\"https://demo.io/problem_details/out_of_credit\",\"title\":\"You do not have enough credit.\",\"status\":403,\"detail\":\"Your current balance is 30, but that costs 50.\",\"instance\":\"/accounts/1\",\"balance\":30,\"accounts\":[\"/accounts/1\",\"/accounts/10\"]}"
|
225
225
|
|
226
226
|
# #<Struct:Petail::Payload:0x00007670
|
227
227
|
# detail = "Your current balance is 30, but that costs 50.",
|
@@ -235,7 +235,7 @@ Petail.from_json "{\"type\":\"https://test.io/problem_details/out_of_credit\",\"
|
|
235
235
|
# instance = "/accounts/1",
|
236
236
|
# status = 403,
|
237
237
|
# title = "You do not have enough credit.",
|
238
|
-
# type = "https://
|
238
|
+
# type = "https://demo.io/problem_details/out_of_credit"
|
239
239
|
# >
|
240
240
|
----
|
241
241
|
|
@@ -246,7 +246,7 @@ XML is supported too but isn't as robust as JSON support, at the moment. This is
|
|
246
246
|
[source,ruby]
|
247
247
|
----
|
248
248
|
payload = Petail[
|
249
|
-
type: "https://
|
249
|
+
type: "https://demo.io/problem_details/out_of_credit",
|
250
250
|
title: "You do not have enough credit.",
|
251
251
|
status: 403,
|
252
252
|
detail: "Your current balance is 30, but that costs 50.",
|
@@ -263,13 +263,13 @@ This means you can serialize as follows:
|
|
263
263
|
[source,ruby]
|
264
264
|
----
|
265
265
|
payload.to_xml
|
266
|
-
# "<?xml version='1.0' encoding='UTF-8'?><problem xmlns='urn:ietf:rfc:7807'><type>https://
|
266
|
+
# "<?xml version='1.0' encoding='UTF-8'?><problem xmlns='urn:ietf:rfc:7807'><type>https://demo.io/problem_details/out_of_credit</type><title>You do not have enough credit.</title><status>403</status><detail>Your current balance is 30, but that costs 50.</detail><instance>/accounts/1</instance><balance>30</balance><accounts><i>/accounts/1</i><i>/accounts/10</i></accounts></problem>"
|
267
267
|
|
268
268
|
payload.to_xml indent: 2
|
269
269
|
# <?xml version='1.0' encoding='UTF-8'?>
|
270
270
|
# <problem xmlns='urn:ietf:rfc:7807'>
|
271
271
|
# <type>
|
272
|
-
# https://
|
272
|
+
# https://demo.io/problem_details/out_of_credit
|
273
273
|
# </type>
|
274
274
|
# <title>
|
275
275
|
# You do not have enough credit.
|
@@ -306,7 +306,7 @@ You can also deserialize by taking the result of the above and turning the raw J
|
|
306
306
|
payload = Petail.from_xml <<~XML
|
307
307
|
<?xml version='1.0' encoding='UTF-8'?>
|
308
308
|
<problem xmlns='urn:ietf:rfc:7807'>
|
309
|
-
<type>https://
|
309
|
+
<type>https://demo.io/problem_details/out_of_credit</type>
|
310
310
|
<title>You do not have enough credit.</title>
|
311
311
|
<status>403</status>
|
312
312
|
<detail>Your current balance is 30, but that costs 50.</detail>
|
@@ -331,10 +331,75 @@ XML
|
|
331
331
|
# instance = "/accounts/1",
|
332
332
|
# status = 403,
|
333
333
|
# title = "You do not have enough credit.",
|
334
|
-
# type = "https://
|
334
|
+
# type = "https://demo.io/problem_details/out_of_credit"
|
335
335
|
# >
|
336
336
|
----
|
337
337
|
|
338
|
+
=== Examples
|
339
|
+
|
340
|
+
There is a lot of useful information you can provide in your problem details depending on the context you are working in. Some have been shown above but here's a few more that might be of interest.
|
341
|
+
|
342
|
+
==== HATEOAS
|
343
|
+
|
344
|
+
With link:https://nordicapis.com/tools-to-make-hateoas-compliance-easier[HATEOAS], you can provide additional information and links for which the client can understand what next actions are available. The below example shows how you can provide additional resources for clients to adjust accordingly:
|
345
|
+
|
346
|
+
[source,ruby]
|
347
|
+
----
|
348
|
+
Petail[
|
349
|
+
type: "https://demo.io/problem_details/rate_limit",
|
350
|
+
title: "Rate limit exceeded",
|
351
|
+
status: 429,
|
352
|
+
detail: "You have exceeded your rate limit of 150 requests per minute",
|
353
|
+
instance: "/articles",
|
354
|
+
extensions: {
|
355
|
+
retry_after: 5,
|
356
|
+
links: [
|
357
|
+
{
|
358
|
+
ref: "self",
|
359
|
+
href: "/articles"
|
360
|
+
},
|
361
|
+
{
|
362
|
+
rel: "retry",
|
363
|
+
href: "/articles",
|
364
|
+
title: "Retry after five minutes"
|
365
|
+
},
|
366
|
+
{
|
367
|
+
rel: "status",
|
368
|
+
href: "/statuses/rate_limit",
|
369
|
+
title: "Check current rate limit usage"
|
370
|
+
}
|
371
|
+
]
|
372
|
+
}
|
373
|
+
]
|
374
|
+
----
|
375
|
+
|
376
|
+
==== Semantic Structure
|
377
|
+
|
378
|
+
In other situations, you might need a different structure in order to aid clients that might be AI driven which needs a semantically structured response in order to course correct. Example:
|
379
|
+
|
380
|
+
[source,ruby]
|
381
|
+
----
|
382
|
+
Petail[
|
383
|
+
type: "https://demo.io/problem_details/invalid_field",
|
384
|
+
title: "Invalid field value",
|
385
|
+
status: 400,
|
386
|
+
detail: "The category requested doesn't exist",
|
387
|
+
instance: "/categories",
|
388
|
+
extensions: {
|
389
|
+
parameters: {
|
390
|
+
category_id: 123
|
391
|
+
},
|
392
|
+
suggestions: [
|
393
|
+
"ruby",
|
394
|
+
"git",
|
395
|
+
"htmx"
|
396
|
+
]
|
397
|
+
}
|
398
|
+
]
|
399
|
+
----
|
400
|
+
|
401
|
+
With the above, the client now knows what parameters where invalid along with relevant suggestions for proceeding. Even better, the suggestions implicitly show the types of IDs that are required.
|
402
|
+
|
338
403
|
== Development
|
339
404
|
|
340
405
|
To contribute, run:
|
data/petail.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.7.1
|
113
113
|
specification_version: 4
|
114
114
|
summary: A RFC 9457 Problem Details for HTTP APIs implementation.
|
115
115
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|