Changelog
View SourceAll notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[3.0.0] - 2025-05-25
Changed
- BREAKING: The
Liberator.Resource.is_options?/1has been renamed toLiberator.Resource.method_options?/1. This is to adhere to a consistent naming convention that Credo recommends. - BREAKING: The project is now licensed under the AGPL 3.0 (or later) license. If you wish to use this library, your project must be licensed with a compatible license.
Added
- The app now registers
telemetryevents withtelemetry_registry
2.0.0 - 2021-09-06
Changed
- BREAKING: All exceptions have been renamed to add
Exceptionto their name. This is to adhere to a consistent naming convention that Credo recommends.
1.4.0 - 2021-03-23
Added
New Callbacks
- The
handle_error/3handler has been added. This is a special handler that lets you manipulate theconnafter an error is raised, so you can choose your status code and body yourself. (docs) (#33) - The
maximum_entity_length/1function. This is used by thevalid_entity_length?/1callback. If the size of the request body is above this size, Liberator will return a status of413 Request Entity Too Large. (docs) - Added the
well_formed?/1function. This function checks the request for general adherence to some form, like if it is valid JSON. It replacesmalformed?/1so that you can return some data after you check for form. (docs) - Added the
body_exists?/1function. This is an internal function that, uh, checks to see if the body exists. If it does, it'll grab it, and callvalid_entity_length?/1and the newwell_formed?/1function. So now you can parse the body if it's there, without worrying about conditional logic if it's not there. (docs
Additions to callbacks
- You can now return the given conn in decision functions and actions to serve as an affirmative response,
as an alternative to returning a plain map, or
true. Now you can modify the conn as you see fit. - You can now return
:okor:errortuples from decisions, actions, and handlers. Returning{:error, term}will invoke the newhandle_error/3function.
Added internationalization
- Internationalization is now supported via
Gettext! Liberator already finds the best language for each request, now it also sets the locale usingGettext.put_locale/1. Just callgettextdirectly in your Resources. (docs) (#8, #10)
Debugging and tracing upgrades
- Tracing individual step duration is now available.
Access the
:durationkey for each decision in the tracing list to get that decision's duration, in native time units. - You can now generate a Graphviz file for either the default decision tree or your own resource's decision tree using the
mix liberator.chartmix task. - Telemetry is now sent upon each request.
Three events
[:liberator, :request, :start],[:liberator, :request, :stop], and[:liberator, :request, :exception]are sent. See the docs forLiberator.Resourcefor more information.
Docs for debugging and tracing
Changed
- The
Varyheader is now served by default, with a value ofAccept-EncodingandAccept-Language. - Now serves the
locationheader if you've returned a map with the:locationkey, or assigned it on the conn. - Some decision functions were rearranged.
- Raised errors are now wrapped in custom exceptions. They're the same errors with the same messages, just with different wrapper types.
- Entries in the trace list have changed from tuples to maps in order to support more tracing information.
The step is now a map member named
:step, and the value is:value
Deprecated
- The
malformed?/1is now deprecated, usewell_formed?/1instead. This lets that decision function return data, and it's the ideal place for parsing the body. (#15)
Fixed
- The
etagheader is now included in the response, if you have overridden it. (#17) - Now serves the
last-modifiedheader based on the return value from thelast_modified/1callback. (#18) - Non-printable-
Stringreturn values from handlers will now be passed throughinspect/1when the content type istext/plain. Printable strings will be passed through without hassle. (#7) - All responses now include an
allowheader, fixing the cases where one was required but not provided, like in anOPTIONSrequest, and when returning a 405 Method Not Allowed. (#9, #12)
1.3.0 - 2020-10-13
Added
- The
:logargument to the:traceoption. Add atrace: :logoption to your module'susestatement, and every request will be logged with a trace. The log message even includes a request ID fromPlug.RequestId, if you have one. (#4) - The
:decision_tree_overridesargument toLiberator.Resource. This is an advanced feature that lets users override parts of the decision tree that Liberator evaluates. Want to change the ordering of some decisions, or add new ones? This is the way! (#5) - The
:handler_status_overridesargument toLiberator.Resource. This is an advanced feature that lets users override status codes associated with handlers. It's mostly useful for those wanting to implement their own new statuses that Liberator doesn't support. - The
:action_followup_overridesargument toLiberator.Resource. This is an advanced feature that lets users override the functions called immediately after actions. It's mostly useful for those wanting to implement their own new actions that Liberator doesn't support.
1.2.0 - 2020-10-12
Added
- The
402 Payment Requiredstatus, along with related callbackspayment_required?andhandle_payment_required/1. - The
451 Unavailable for Legal Reasonsstatus, along with related callbacksunavailable_for_legal_reasons?/1andhandle_unavailable_for_legal_reasons/1. - The
429 Too Many Requestsstatus, along with related callbackstoo_many_requests?/1andhandle_too_many_requests/1. If you return a map containing a:retry_aftervalue, Liberator will use that to set aretry-afterheader. - You can also return a
:retry_aftervalue from any other decision function, likeservice_available?/1, ormoved_permanently?/1, for the same effect. See MDN's docs on theretry-afterheader for more information on why you'd want to do this.
Fixed
- Dates in headers are now parsed properly. (#1)
1.1.0 - 2020-10-04
Added
- This changelog!
- The
:traceoption: Addtrace: :headersto youruse Liberator.Resourcestatement to get anx-liberator-traceheader added to responses, and see the result of all decisions. - Compression options:
deflate,gzip, andidentity.
Changed
- Codecs are now configurable.
Set the
:media_typesand:encodingsmap in Liberator's config to add your own codecs.
Removed
Liberator.Resourceno longer callsuse Timex, so your context is less polluted.
Fixed
- Better wildcard handling during content negotiation
- Content negotiation actually obeys q-values for priority
1.0.0 - 2020-10-02
Added
- Basic decision tree navigation