https://github.com/invetica/media-types
Media types (https://tools.ietf.org/html/rfc2046).
https://github.com/invetica/media-types
api clojure http media-types mime
Last synced: 3 months ago
JSON representation
Media types (https://tools.ietf.org/html/rfc2046).
- Host: GitHub
- URL: https://github.com/invetica/media-types
- Owner: invetica
- License: mit
- Created: 2017-05-29T17:20:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-29T17:23:41.000Z (about 9 years ago)
- Last Synced: 2026-01-01T19:22:51.986Z (5 months ago)
- Topics: api, clojure, http, media-types, mime
- Language: Clojure
- Size: 54.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
*Media Types* knows how to parse, and generate media type strings that you might
use in HTTP content negotiation.
* Contents :TOC:
- [[#why-this-library][Why this library?]]
- [[#usage][Usage]]
- [[#tests][Tests]]
- [[#further-reading][Further Reading]]
- [[#license][License]]
* Why this library?
Other solutions exist but are either a bit too featureful. This library aims to
be small, lightweight, easy to use, and fast.
For a more complete solution that includes detection of file types, can suggest
extensions etc. you might want to check out [[https://tika.apache.org/][Apache Tika]].
* Usage
You can parse a string media type into a map of ~:toptype~, ~:subtype~, and
~:params~, where the media type string is of the form:
#+begin_example
/[; params]+
#+end_example
Given a media type of "application/json; charset=utf-8", we can parse this into
a map like so:
#+begin_src clojure
(require '[invetica.media-types :as media])
(media/parse "application/json; charset=utf-8")
;; => {:params {"charset" "utf-8"}
;; :subtype "javascript"
;; :toptype "application"}
#+end_src
* Tests
The test suite makes sure we can parse every registered media type, which
requires a bit of XML pulled from IANA. This data is vendored into the
repository to save IANA's bandwidth, and to ensure we don't need the internet to
run our tests.
You can pull the latest list of registered media types using curl like so:
#+begin_src bash
mkdir -p dev-resources/invetica
curl -o dev-resources/invetica/media-types.xml \
https://www.iana.org/assignments/media-types/media-types.xml
#+end_src
#+RESULTS:
* Further Reading
- https://tools.ietf.org/html/rfc2046
- https://www.iana.org/assignments/media-types/media-types.xhtml
- https://en.wikipedia.org/wiki/Media_type
* License
The MIT License (MIT)
Copyright © 2017 Invetica Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.