Crate parse_link_header[][src]

A library for parse http link header.

How to use

Note for version 0.1.x

The version 0.1 can't correctly handle the relative ref which described in

The parsed value of version 0.1 refers to the return value of, which is a HashMap with the same structure.

So if you want to parse relative ref, please use version 0.2.

Or if you don't care about relative ref and wanna simple HashMap<String, HashMap<String, String>> result, you can use version 0.1.

Version 0.2.x

In your Cargo.toml, add:

parse_link_header = "0.2"


let link_header = "<>; rel=\"next\", <>; rel=\"last\"";


The parsed value is a Result<HashMap<Option<Rel>, Link>, ()>, which Rel and Link is:

use std::collections::HashMap;

use http::Uri;

#[derive(Debug, PartialEq)]
pub struct Link {
    pub uri: Uri, //
    pub raw_uri: String,
    pub queries: HashMap<String, String>,
    pub params: HashMap<String, String>,

type Rel = String;

You can see why the key of HashMap is Option<Rel> because if you won't provide a rel type, the key will be an empty string.

Refer to, The rel parameter MUST be present.

Therefore, if you find that key is None, please check if you provide the rel type.





Parse link header.