Skip to content

Commit

Permalink
Added missing http methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-cpsn committed Feb 18, 2024
1 parent 9c01d39 commit fc8b415
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ impl App<'_> {
],
..Default::default()
},
Request {
name: "Test Post",
url: "https://httpbin.org/post",
method: Method::POST,
..Default::default()
},
Request {
name: "Test Put",
url: "https://httpbin.org/put",
method: Method::PUT,
..Default::default()
},
Request {
name: "Test Delete",
url: "https://httpbin.org/delete",
method: Method::DELETE,
..Default::default()
},
Request {
name: "Test Patch",
url: "https://httpbin.org/patch",
method: Method::PATCH,
..Default::default()
},
Request {
name: "Rust Homepage",
url: "https://www.rust-lang.org",
Expand Down
6 changes: 4 additions & 2 deletions src/app/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::layout::Direction::{Horizontal, Vertical};
use ratatui::prelude::{Modifier, Style};
use ratatui::style::{Color, Stylize};
use ratatui::style::Color::White;
use ratatui::widgets::{Block, Borders, List, ListItem, Padding, Paragraph};
use ratatui::widgets::block::Title;
use tui_big_text::{BigTextBuilder, PixelSize};
Expand Down Expand Up @@ -167,8 +168,8 @@ impl App<'_> {
let request_header_layout = Layout::new(
Horizontal,
[
Constraint::Percentage(7),
Constraint::Percentage(93)
Constraint::Percentage(10),
Constraint::Percentage(90)
],
)
.split(request_layout[1]);
Expand All @@ -186,6 +187,7 @@ impl App<'_> {

let method_paragraph = Paragraph::new(method.to_string())
.bg(get_method_bg(&method))
.fg(White)
.centered();

frame.render_widget(method_block, request_header_layout[0]);
Expand Down
10 changes: 8 additions & 2 deletions src/request/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ use reqwest::Method;
pub fn get_method_bg(method: &Method) -> Color {
match method {
&Method::GET => Color::Green,
&Method::POST => Color::Yellow,
&Method::POST => Color::Rgb(231, 186, 0),
&Method::PUT => Color::LightBlue,
&Method::DELETE => Color::LightRed,
&Method::PATCH => Color::LightCyan,
_ => Color::Black
}
}

pub fn next_method(method: &Method) -> Method {
match method {
&Method::GET => Method::POST,
&Method::POST => Method::GET,
&Method::POST => Method::PUT,
&Method::PUT => Method::DELETE,
&Method::DELETE => Method::PATCH,
&Method::PATCH => Method::GET,
_ => Method::GET
}
}

0 comments on commit fc8b415

Please sign in to comment.