Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imammubin/328ec9a40b8e304f14f50c87508ef719 to your computer and use it in GitHub Desktop.
Save imammubin/328ec9a40b8e304f14f50c87508ef719 to your computer and use it in GitHub Desktop.
#![allow(unused_imports, non_snake_case)]
use actix_web::{
HttpServer, HttpResponse, App, Responder,
web, get, guard
};
#[actix_web::main]
async fn main()-> std::io::Result<()>{
HttpServer::new(||{
App::new()
.service(index)
// START BLOG Route
.service(
web::scope("/blog")
/* BLOG - HomePage */
.service(
web::resource("")
// .guard(guard::Header("content-type", "application/json"))
.route(web::get().to(blog_home))
)
/* Blog - All Posts */
.service(
web::resource("/posts")
.route(web::post().to(blog_posts_add))
.route(web::get().to(blog_posts))
)
/* BLOG - SinglePage Post */
.service(
web::resource("/{blog_singlepost}")
.route(web::get().to(blog_singlepost))
.route(web::put().to(blog_singlepost_edit))
.route(web::delete().to(blog_singlepost_delete))
)
)
// END BLOG Route
}).bind(("127.0.0.1",8080))?.run().await
}
#[get("/")]
async fn index()->impl Responder{
HttpResponse::Ok().body("INDEX")
}
async fn blog_home()->impl Responder{
HttpResponse::Ok().body("Blog HOME")
}
async fn blog_singlepost(path: web::Path<(String,)>)->impl Responder{
let path=path.into_inner();
HttpResponse::Ok().body(format!("Blog Post GET by ID {}",path.0))
}
async fn blog_singlepost_edit(path: web::Path<(String,)>)->impl Responder{
let path=path.into_inner();
HttpResponse::Ok().body(format!("Blog Post EDIT by ID {}",path.0))
}
async fn blog_singlepost_delete(path: web::Path<(String,)>)->impl Responder{
let path=path.into_inner();
HttpResponse::Ok().body(format!("Blog Post DELETE by ID {}",path.0))
}
async fn blog_posts()->impl Responder{
HttpResponse::Ok().body(format!("Blog List All Post "))
}
async fn blog_posts_add()->impl Responder{
HttpResponse::Ok().body(format!("Blog Post Add New"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment