Repository: nushell/nushell
File: crates/nu-command/src/network/http/http_.rs (Rust)

Code before:
            .category(Category::Network)
    }

    fn description(&self) -> &str {
        "Various commands for working with http methods."
    }

    fn extra_description(&self) -> &str {
        "Without a subcommand but with a URL provided, it performs a GET request by default or a POST request if data is provided. You can use one of the following subcommands. Using this command as-is will only display this help message."
    }

    fn search_terms(&self) -> Vec<&str> {
        vec![
            "network", "fetch", "pull", "request", "download", "curl", "wget",
        ]
    }

    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let url = call.opt::<Value>(engine_state, stack, 0).ok().flatten();
        let data = call.opt::<Value>(engine_state, stack, 1).ok().flatten();
        match (url.is_some(), data.is_some()) {
            (true, true) => run_post(engine_state, stack, call, input),
            (true, false) => run_get(engine_state, stack, call, input),
            (false, true) => panic!("Impossible state: data provided without a URL"),
            (false, false) => Ok(Value::string(
                get_full_help(self, engine_state, stack),
                call.head,
            )
            .into_pipeline_data()),
        }
    }
}


Review comment (suggestion):
I think use can just use `?`.
```nushell
       let url: Option<Value> = call.opt(engine_state, stack, 0)?;
       let data: Option<Value> = call.opt(engine_state, stack, 1)?;
```

Code after:
    }

    fn description(&self) -> &str {
        "Various commands for working with http methods."
    }

    fn extra_description(&self) -> &str {
        "Without a subcommand but with a URL provided, it performs a GET request by default or a POST request if data is provided. You can use one of the following subcommands. Using this command as-is will only display this help message."
    }

    fn search_terms(&self) -> Vec<&str> {
        vec![
            "network", "fetch", "pull", "request", "download", "curl", "wget",
        ]
    }

    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let url = call.opt::<Value>(engine_state, stack, 0)?;
        let data = call.opt::<Value>(engine_state, stack, 1)?;
        match (url.is_some(), data.is_some()) {
            (true, true) => run_post(engine_state, stack, call, input),
            (true, false) => run_get(engine_state, stack, call, input),
            (false, true) => Err(ShellError::NushellFailed {
                msg: (String::from("Default verb is get with a payload. Impossible state")),
            }),
            (false, false) => Ok(Value::string(
                get_full_help(self, engine_state, stack),
                call.head,
            )
            .into_pipeline_data()),
        }
    }

    fn examples(&self) -> Vec<Example> {
        vec![
            Example {
                description: "Get content from example.com with default verb",
                example: "http https://www.example.com",
                result: None,
            },
            Example {
                description: "Post content to example.com with default verb",
                example: "http https://www.example.com 'body'",
                result: None,
            },