Giter VIP home page Giter VIP logo

jelly-restdb-final's Introduction

Springboot REST -> DB

run

./gradlew bootRun

API

API DETAIL

select API

$ curl -I http://localhost:8080/people
HTTP/1.1 204
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Link: <http://localhost:8080/people>;rel="self",<http://localhost:8080/profile/people>;rel="profile",<http://localhost:8080/people/search>;rel="search"
Date: Wed, 06 Mar 2024 02:47:14 GMT

$ curl http://localhost:8080/people
{
  "_embedded" : {
    "people" : [ ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/people?page=0&size=20"
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/people"
    },
    "search" : {
      "href" : "http://localhost:8080/people/search"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 0,
    "totalPages" : 0,
    "number" : 0
  }
}%

$ curl http://localhost:8080/people/1
{
  "firstName" : "Frodo",
  "lastName" : "Baggins",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/people/1"
    },
    "person" : {
      "href" : "http://localhost:8080/people/1"
    }
  }
}%

insert API

$ curl -i -H "Content-Type:application/json" -d '{"firstName": "Frodo", "lastName": "Baggins"}' http://localhost:8080/people
HTTP/1.1 201
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Location: http://localhost:8080/people/1
Content-Type: application/hal+json
Transfer-Encoding: chunked
Date: Wed, 06 Mar 2024 02:50:04 GMT

{
  "firstName" : "Frodo",
  "lastName" : "Baggins",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/people/1"
    },
    "person" : {
      "href" : "http://localhost:8080/people/1"
    }
  }
}%

dockerize

$ ./gradlew clean bootJar
$ docker build --platform linux/amd64 --build-arg JAR_FILE=build/libs/restdb-0.2.0-SNAPSHOT.jar -f docker/Dockerfile -t restdb:0.2.0 .
$ docker run --platform linux/amd64 -d --name restdb020 -p 8020:8080 restdb:0.2.0

docker compose

$ docker compose -f docker-compose.yml up -d --force-recreate --build

proxy

$ curl -Iv  http://localhost:8888/people/1
*   Trying 127.0.0.1:8888...
* Connected to localhost (127.0.0.1) port 8888 (#0)
> HEAD /people/1 HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.84.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
HTTP/1.1 200
< Server: nginx/1.25.4
Server: nginx/1.25.4
< Date: Wed, 06 Mar 2024 11:25:59 GMT
Date: Wed, 06 Mar 2024 11:25:59 GMT
< Content-Type: application/hal+json
Content-Type: application/hal+json
< Connection: keep-alive
Connection: keep-alive
< Vary: Origin
Vary: Origin
< Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
Vary: Access-Control-Request-Headers

<
* Connection #0 to host localhost left intact


$ curl http://localhost:8888/people/1 | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   204    0   204    0     0   3702      0 --:--:-- --:--:-- --:--:--  4000
{
  "firstName": "Gil Dong",
  "lastName": "Hong",
  "_links": {
    "self": {
      "href": "http://rest:8080/people/1"
    },
    "person": {
      "href": "http://rest:8080/people/1"
    }
  }
}
$ curl http://localhost:8888/people/1 | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   204    0   204    0     0   3634      0 --:--:-- --:--:-- --:--:--  4250
{
  "firstName": "Gil Dong",
  "lastName": "Hong",
  "_links": {
    "self": {
      "href": "http://rest:8080/people/1"
    },
    "person": {
      "href": "http://rest:8080/people/1"
    }
  }
}

cache

$ docker exec restdb-proxy-1 tail -n 6 /var/log/nginx/api-proxy.access.log
172.27.0.1 - - [06/Mar/2024:12:32:11 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=EXPIRED
172.27.0.1 - - [06/Mar/2024:12:32:12 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=HIT
172.27.0.1 - - [06/Mar/2024:12:32:12 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=HIT
172.27.0.1 - - [06/Mar/2024:12:32:13 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=HIT
172.27.0.1 - - [06/Mar/2024:12:32:14 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=HIT
172.27.0.1 - - [06/Mar/2024:12:32:15 +0000] "HEAD /people/1 HTTP/1.1" 200 0 "-" "curl/7.84.0" cs=HIT


$ docker exec restdb-proxy-1 cat /etc/nginx/conf.d/proxy.conf
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=100m inactive=1m use_temp_path=off;

log_format cache '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" cs=$upstream_cache_status';
server {
    listen 80;

    ## Access and error logs.
    access_log /var/log/nginx/api-proxy.access.log cache;
    error_log  /var/log/nginx/api-cache.error.log;

    location / {
        proxy_pass http://rest:8080;

        # proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
        proxy_cache_valid 200 302 5s;
        proxy_cache_valid 404 1m;

        proxy_cache my_cache;
        # proxy_cache_valid 24h;
        # proxy_cache_methods GET POST;
    }
}%

init

image

ref

jelly-restdb-final's People

Contributors

becky2sawyer avatar pysatellite avatar jaelinny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.