Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #52 from obsidian-rs/develop
Browse files Browse the repository at this point in the history
Version 0.2
  • Loading branch information
jk-gan committed Apr 23, 2020
2 parents c264450 + b104305 commit aa0df97
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ path = 'examples/app_state.rs'

[package]
name = 'obsidian'
version = '0.2.0-alpha.1'
version = '0.2.0'
authors = [
'Gan Jun Kai <[email protected]>',
'Wai Pai Lee <[email protected]>',
]
edition = '2018'
description = 'A Rust framework'
description = 'Ergonomic async http framework for amazing, reliable and efficient web'
readme = "README.md"
homepage = "https://obsidian-rs.github.io"
repository = 'https://github.com/obsidian-rs/obsidian'
license = 'MIT'
keywords = [
'obsidian',
'async',
'http',
'web',
'framework'
]
categories = ["asynchronous", "web-programming::http-server", "network-programming"]

[dependencies]
hyper = '0.13.1'
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
</a>
</div>

<p align="center"><strong>Obsidian</strong> is a Rust web framework with a vision to make Rust web development fun.</p>
<p align="center"><strong>Obsidian</strong> is an ergonomic Rust async http framework for reliable and efficient web.</p>

## Hello World

```rust
use obsidian::App;

#[tokio::main]
async fn main() {
let mut app = App::new();
let mut app: App = App::new();
let addr = ([127, 0, 0, 1], 3000).into();

app.get("/", |ctx: Context| async { ctx.build("Hello World").ok() });
Expand All @@ -37,6 +38,7 @@ async fn main() {
```

## Hello World (with handler function)

```rust
use obsidian::{context::Context, App, ContextResult};

Expand All @@ -47,7 +49,7 @@ async fn hello_world(ctx: Context) -> ContextResult {

#[tokio::main]
async fn main() {
let mut app = App::new();
let mut app: App = App::new();
let addr = ([127, 0, 0, 1], 3000).into();

app.get("/", hello_world);
Expand All @@ -60,6 +62,7 @@ async fn main() {
```

## JSON Response

```rust
use obsidian::{context::Context, App, ContextResult};
use serde::*;
Expand Down Expand Up @@ -103,4 +106,4 @@ cargo run --example example

## Current State

NOT READY FOR PRODUCTION!
NOT READY FOR PRODUCTION YET!
12 changes: 5 additions & 7 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ ctx.build(Response::ok().html("<!DOCTYPE html><html><head><link rel=\"shotcut ic
app.get("/json", |ctx: Context| async {
let point = Point { x: 1, y: 2 };

ctx.build(
Response::created()
.set_header(header::AUTHORIZATION, "token")
.set_header_str("X-Custom-Header", "Custom header value")
.json(point),
)
.ok()
ctx.build_json(point)
.with_status(StatusCode::OK)
.with_header(header::AUTHORIZATION, "token")
.with_header_str("X-Custom-Header", "Custom header value")
.ok()
});

app.get("/json-with-headers", |ctx: Context| async {
Expand Down
8 changes: 8 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,24 @@ impl ResponseBuilder {
ResponseBuilder { ctx, response }
}

/// set http status code for response
pub fn with_status(mut self, status: StatusCode) -> Self {
self.response = self.response.set_status(status);
self
}

/// set http header for response
pub fn with_header(mut self, key: HeaderName, value: &'static str) -> Self {
self.response = self.response.set_header(key, value);
self
}

/// set custom http header for response with `&str` key
pub fn with_header_str(mut self, key: &'static str, value: &'static str) -> Self {
self.response = self.response.set_header_str(key, value);
self
}

pub fn with_headers(mut self, headers: Vec<(HeaderName, &'static str)>) -> Self {
self.response = self.response.set_headers(headers);
self
Expand Down

0 comments on commit aa0df97

Please sign in to comment.