An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# ContentType

[![CI](https://github.com/rdf-elixir/content_type/workflows/CI/badge.svg?branch=master)](https://github.com/rdf-elixir/content_type/actions?query=branch%3Amaster+workflow%3ACI)
[![Hex.pm](https://img.shields.io/hexpm/v/content_type.svg?style=flat-square)](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.