https://github.com/rdf-elixir/content_type
An Elixir parser for HTTP Content-Type headers
https://github.com/rdf-elixir/content_type
content-type elixir http parser
Last synced: 7 days ago
JSON representation
An Elixir parser for HTTP Content-Type headers
- Host: GitHub
- URL: https://github.com/rdf-elixir/content_type
- Owner: rdf-elixir
- License: other
- Created: 2018-03-03T21:48:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-05T23:17:25.000Z (over 4 years ago)
- Last Synced: 2026-05-06T00:12:44.526Z (about 2 months ago)
- Topics: content-type, elixir, http, parser
- Language: Elixir
- Homepage: https://hex.pm/packages/content_type
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ContentType
[](https://github.com/rdf-elixir/content_type/actions?query=branch%3Amaster+workflow%3ACI)
[](https://hex.pm/packages/content_type)
A pure Elixir parser for HTTP Content-Type headers.
It's an extraction from [Plug](https://github.com/elixir-plug/plug) by Plataformatec.
## Installation
Add `content_type` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:content_type, "~> 0.1.0"}
]
end
```
## Usage
Parsing a content type:
```elixir
import ContentType
content_type "text/plain"
# => {:ok, "text", "plain", %{}}
content_type "x-sample/json; charset=utf-8"
# => {:ok, "x-sample", "json", %{"charset" => "utf-8"}}
content_type "APPLICATION/vnd.ms-data+XML"
# => {:ok, "application", "vnd.ms-data+xml", %{}}
content_type "x/*"
# => :error
```
Parsing a media type (with potential wildcards):
```elixir
import ContentType
media_type "x/*"
# => {:ok, "x", "*", %{}}
media_type "text/*; q=1.0"
# => {:ok, "text", "*", %{"q" => "1.0"}}
media_type "x y"
# => :error
```
## License
The source code is released under Apache 2 License.
Check LICENSE file for more information.