Skip to content

Sample Responses #16

@tomharmon

Description

@tomharmon

Feature Request

Add ability to store sample responses for requests. I'm opening this issue to get feedback on how to implement before going ahead and doing it

Motivation

it's in the TODO and I want to contribute

Proposal

A possibility would be to update the RequestKind like so:

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SampleResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub body: Option<String>,
    #[serde(skip_serializing_if = "IndexMap::is_empty")]
    pub headers: IndexMap<String, Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cookies: Option<CookieStore>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<u16>,
}

/// we store requests on a collection and on directories as a enum that could
/// be either an request or a directory. This enables us to have nested
/// directories, although we don't support that now and might not ever support.
///
/// Single means its a request
/// SingleWithSampleResp means its a request with a sample response
/// Nested means its a directory
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum RequestKind {
    Single(Arc<RwLock<Request>>),
    SingleWithSampleResp {
        request: Arc<RwLock<Request>>,
        sample_response: SampleResponse,
    },
    Nested(Directory),
}

I was thinking that the TUI could show sample responses in the preview window. We could use some kind of icon next to preview to indicate that a sample response is available. Then the user could press a key to switch from regular Preview of an actual request to the sample response preview.

Preview (S *)
Pretty | Raw | Headers | Cookies

like this, where the * or something could indicate a sample response is present.

Alternatives

open to suggestions

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions