Created
          July 13, 2021 22:09 
        
      - 
      
- 
        Save mayankchoubey/9a990421f33d9d7519397f73770ddb65 to your computer and use it in GitHub Desktop. 
    Deno native HTTP v/s Spring Boot HTTP
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.example.demo; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| import org.springframework.web.bind.annotation.PostMapping; | |
| import org.springframework.web.bind.annotation.RequestBody; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.http.HttpStatus; | |
| import org.springframework.web.bind.annotation.RestController; | |
| @SpringBootApplication | |
| @RestController | |
| public class DemoApplication { | |
| public static void main(String[] args) { | |
| SpringApplication.run(DemoApplication.class, args); | |
| } | |
| @PostMapping("/") | |
| public ReqName handleRequest(@RequestBody ReqName rBody) { | |
| return rBody; | |
| } | |
| } | |
| class ReqName{ | |
| private String name; | |
| public String getName() { | |
| return name; | |
| } | |
| public void setName(String name) { | |
| this.name = name; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const listener = Deno.listen({ port: 3000 }); | |
| for await(const conn of listener) | |
| handleNewConnection(conn); | |
| async function handleNewConnection(conn: Deno.Conn) { | |
| for await(const { request, respondWith } of Deno.serveHttp(conn)) { | |
| const reqBody=await request.json(); | |
| if(reqBody) { | |
| respondWith(new Response(JSON.stringify({ name: reqBody.name }), { | |
| headers: { 'content-type': 'application/json'} | |
| })); | |
| } else | |
| respondWith(new Response(undefined, {status: 400})); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment