{"id":50140322,"url":"https://github.com/stanislawbartkowski/restapijson","last_synced_at":"2026-05-24T01:01:25.419Z","repository":{"id":43388992,"uuid":"342975174","full_name":"stanislawbartkowski/RestApiJSon","owner":"stanislawbartkowski","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-22T23:50:40.000Z","size":290,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-23T01:23:17.268Z","etag":null,"topics":["java","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stanislawbartkowski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-02-27T22:51:16.000Z","updated_at":"2026-05-22T23:45:26.000Z","dependencies_parsed_at":"2024-05-04T00:22:16.856Z","dependency_job_id":null,"html_url":"https://github.com/stanislawbartkowski/RestApiJSon","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stanislawbartkowski/RestApiJSon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislawbartkowski%2FRestApiJSon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislawbartkowski%2FRestApiJSon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislawbartkowski%2FRestApiJSon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislawbartkowski%2FRestApiJSon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanislawbartkowski","download_url":"https://codeload.github.com/stanislawbartkowski/RestApiJSon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislawbartkowski%2FRestApiJSon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33417489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T22:14:44.296Z","status":"ssl_error","status_checked_at":"2026-05-23T22:14:43.778Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","rest-api"],"created_at":"2026-05-24T01:01:00.701Z","updated_at":"2026-05-24T01:01:25.383Z","avatar_url":"https://github.com/stanislawbartkowski.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RestApiJSon\n\n\u003e mvn package -Dmaven.test.skip=true\u003cbr\u003e\n\u003e mvn deploy -Dmaven.test.skip=true\u003cbr\u003e\n\n# Docker/Podman\n\n## Package\n\n\u003e cd docker\u003cbr\u003e\n\u003e mvn package\u003cbr\u003e\n\nVerify target\u003cbr\u003e\n\n\u003e ll target\u003cbr\u003e\n\n```\n-rw-r--r--. 1 sbartkowski users     2106 11-04 01:50 restapijdbc-1.0-SNAPSHOT.jar\n-rw-r--r--. 1 sbartkowski users 11873250 11-05 00:55 restapijdbc-1.0-SNAPSHOT-jar-with-dependencies.jar\n```\n\n## Docker image\n\nAny additional JDBC drivers should be put in *jdbc* directory.\u003cbr\u003e\n\u003cbr\u003e\nThe docker image name is *restapijdbc*.\u003cbr\u003e\n\nThe script is using *openjdk:11-jre-slim-buster* as the base image. The final image contains also *python3* and\n*JayDeBeApi* package.\n\n\u003e ./crimage.sh\u003cbr\u003e\n\n```\n.......\nSTEP 10: WORKDIR ${WDIR}\n--\u003e 406a1bfa9ac\nSTEP 11: CMD [\"bash\",\"-c\",\"./run.sh\"]\nSTEP 12: COMMIT restapijdbc\n--\u003e 7f28f25554c\nSuccessfully tagged localhost/restapijdbc:latest\n7f28f25554c1bc4103afb07e72ce951c5209c5c4c4d583fb1e970e18f43a0396\n```\n\n## Create container\n\n| Parameter   | Description                                                                                                                                                | Example                                                               \n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------- \n| -p          | 8080: port exposed, can be redirected, port is nonsecure                                                                                                   | -p 8080:8080                                                          \n| -e DB       | Database used. The following values are accepted: mysql, postgres, db2                                                                                     | -e DB=postgres                                                        \n| -e USER     | Database user                                                                                                                                              | -e USER=queryuser                                                     \n| -e PASSWORD | User password                                                                                                                                              | -e PASSWORD=secret                                                    \n| -e URL      | JDBC connnection string                                                                                                                                    | -e URL=jdbc:mysql://kist:3306/querydb                                 \n| -v Volume   | */var/resource* volume should be mounted to customer resources. The custom resource directory could contain subdirectorie: *python*, *resoudir*, *restdir* | -v  /home/sbartkowski/work/restmysqlmodel/resources/:/var/resources:Z \n\n## PostgreSQL\n\n\u003e podman run --name=mypostgres -v /home/sbartkowski/work/restmysqlmodel/resources/:/var/resources:Z -p 8080:8080 -e\n\u003e USER=queryuser -e PASSWORD=secret -e DB=postgres -e URL=jdbc:postgresql://kist:5432/querydb -d restapijdbc\n\n## MySQL/MariaDB\n\n\u003e podman run --name=mymysql -v /home/sbartkowski/work/restmysqlmodel/resources/:/var/resources:Z -p 8080:8080 -e\n\u003e USER=queryuser -e PASSWORD=secret -e DB=mysql -e URL=jdbc:mysql://kist:3306/querydb -d restapijdbc\n\n## DB2\n\nTo access DB2, the *restapijdbc* image is expected to contain DB2 JDBC driver jar. Before running *crimage.sh* command,\nthe DB2 JDBC driver jar should be copied to *jdbc* directory.\u003cbr\u003e\n\n\u003e podman run --name=mydb2 -v /home/sbartkowski/work/restmysqlmodel/resources/:/var/resources:Z -p 8080:8080 -e\n\u003e USER=db2inst1 -e PASSWORD=secret123 -e DB=db2 -e URL=jdbc:db2://thinkde:50000/querydb -d restapijdbc\n\n# OpenShift/Kubernetes\n\n## Push image to quay.io\n\nImage in local repository is created after running *./crimage.sh*\n\nTag the local image, use valid *quay.io* repository name.\u003cbr\u003e\n\n\u003e podman login quay.io\u003cbr\u003e\n\u003e podman tag restapijdbc quay.io/stanislawbartkowski/restapijdbc:latest\u003cbr\u003e\n\u003e podman push quay.io/stanislawbartkowski/restapijdbc:latest\u003cbr\u003e\n\n```\n...........\nCopying blob 8276ab1df2fb done  \nCopying blob f73c57e2b056 done  \nCopying blob 1a86b0b1243f skipped: already exists  \nCopying blob 85d5baf8a9db skipped: already exists  \nCopying blob f1ab4986f47c skipped: already exists  \nCopying blob e81bff2725db skipped: already exists  \nCopying blob bf70f8970630 done  \nCopying config 8bc51ffeaa done  \nWriting manifest to image destination\nCopying config 8bc51ffeaa [--------------------------------------] 0.0b / 6.2KiB\nWriting manifest to image destination\nStoring signatures\n\n```\n\n## Create OpenShift project/namespace\n\n\u003e oc new-project restapijdbc\u003cbr\u003e\n\n## Create OpenShift object manually\n\n### Create volume\n\n*restapijdbc* service requires customized resources with REST/API definitions. Keep container and resource definition\nseparated to allow independent updates. Adjust StorageClass and storage capacity accordingly.\u003cbr\u003e\n\n```\noc create -f - \u003c\u003cEOF\nkind: PersistentVolumeClaim\napiVersion: v1\nmetadata:\n  name: restapijdbc\n  annotations:\n    volume.beta.kubernetes.io/storage-class: \"managed-nfs-storage\"\nspec:\n  accessModes:\n    - ReadWriteMany\n  resources:\n    requests:\n      storage: 1Mi\nEOF\n```\n\n\u003e oc get pvc\u003cbr\u003e\n\n```\nNAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE\nrestapijdbc   Bound    pvc-57521d05-8ddd-4c7b-94f9-d30b5898583a   1Mi        RWX            managed-nfs-storage   7s\n```\n\n### Create secret with database user and password\n\n\u003e oc create secret generic mysql --from-literal USER=queryuser --from-literal PASSWORD=secret\u003cbr\u003e\n\n\u003e oc get secret\u003cbr\u003e\n\n```\nNAME                       TYPE                                  DATA   AGE\n...\nmysql                      Opaque                                2      7s\n```\n\n### Create deployment\n\n| Env variable | Description                           | Example                                             \n|--------------|---------------------------------------|-----------------------------------------------------|\n| DB           | Database type: mysql, db2 or postgres | --env DB=mysql                                      \n| URL          | JDBC connection string                | -env URL=\"jdbc:mysql://172.30.171.241:3306/querydb\" \n\n\u003e oc new-app --docker-image=quay.io/stanislawbartkowski/restapijdbc --name restapijdbc --env DB=mysql --env URL=\"jdbc:\n\u003e mysql://172.30.171.241:3306/querydb\" \u003cbr\u003e\n\nAssign secret\u003cbr\u003e\n\n\u003e oc set env deployment/restapijdbc --from secret/mysql\u003cbr\u003e\n\nAssign persistent volume\u003cbr\u003e\n\n\u003e oc set volume deployment/restapijdbc --add --name=restapijdbc-volume-1 -t pvc --claim-name=restapijdbc --overwrite\u003cbr\u003e\n\n\u003e oc get pods\u003cbr\u003e\n\n```\nNAME                          READY   STATUS    RESTARTS   AGE\nrestapijdbc-b54d54cff-lzj8m   1/1     Running   0          67s\n```\n\nVerify logs\u003cbr\u003e\n\n\u003e oc logs restapijdbc-b54d54cff-lzj8m\u003cbr\u003e\n\n```\nDatabase type: mysql\nLooking for JDBC jar file according to mysql\nexec java -cp mysql-connector-java-8.0.27.jar:restapijdbc-1.0-SNAPSHOT-jar-with-dependencies.jar RestMain -c rest.properties -p 8080\nNov 06, 2021 11:16:44 AM com.rest.restservice.RestLogger info\n.....\nINFO: user value read:queryuser\nNov 06, 2021 11:16:45 AM com.rest.restservice.RestLogger info\nINFO: password value read:XXXXXXXX\nNov 06, 2021 11:16:45 AM com.rest.runjson.executors.sql.JDBC connect\nINFO: Connecting to jdbc:mysql://172.30.171.241:3306/querydb user queryuser\nNov 06, 2021 11:16:45 AM com.rest.runjson.executors.sql.JDBC connect\nINFO: Connected\nNov 06, 2021 11:16:45 AM com.rest.restservice.RestLogger info\nINFO: Start HTTP Server, listening on port 8080\nNov 06, 2021 11:16:45 AM com.rest.restservice.RestLogger info\nINFO: Register service: {root}\n```\n\n### External access\n\nCreate NodePort\u003cbr\u003e\n\n```\ncat \u003c\u003cEOF |oc apply -f -\napiVersion: v1\nkind: Service\nmetadata:\n  name: restapijdbcn\nspec:\n  selector:           \n   deployment: restapijdbc\n  type: NodePort\n  ports:\n  - port: 8080\n    protocol: TCP\n    targetPort: 8080\n    nodePort: 30819\nEOF\n```\n\nConfigure port redirection on HAProcy host. External port is defined as 7999.\u003cbr\u003e\n\u003e vi /etc/haproxy/haproxy.cfg\u003cbr\u003e\n\n```\nfrontend ingress-rest\n        bind *:7999\n        default_backend ingress-rest\n        mode tcp\n        option tcplog\n\nbackend ingress-rest\n        balance source\n        mode tcp\n        server master0 10.17.43.9:30819 check\n        server master1 10.17.46.40:30819 check\n        server master2 10.17.48.179:30819 check\n        server worker0 10.17.57.166:30819 check\n        server worker1 10.17.59.104:30819 check\n        server worker2 10.17.61.175:30819 check\n```\n\n\u003e systemctl restart haproxy\n\n## OpenShift template\n\nAll necessary object can be created through OpenShift template.\u003cbr\u003e\n\n\u003cbr\u003e\n\n\u003e curl -s https://raw.githubusercontent.com/stanislawbartkowski/RestApiJSon/main/docker/restapijdbc.yaml | oc create\n\u003e -f -\u003cbr\u003e\n\u003cbr\u003e\n\n\u003e oc process --parameters restapijdbc\n\n```\nNAME                DESCRIPTION                              GENERATOR           VALUE\nURL                 Database access URL string                                   \nDB                  Values allowed, db2, postgres or mysql                       \nUSER                User to access the database                                  \nPASSWORD            Password to access the database      \n```\n\nThe *USER* and *PASSWORD* parameter are expected as base64 string. \u003cbr\u003e\n\u003cbr\u003e\n\u003e echo queryuser | openssl base64\u003cbr\u003e\n\n```\ncXVlcnl1c2VyCg==\n```\n\n\u003e echo secret | openssl base64\u003cbr\u003e\n\n```\nc2VjcmV0Cg==\n```\n\nBuild the service.\u003cbr\u003e\n\n\u003e oc new-app --template=restapijdbc -p DB=mysql -p USER=\"cXVlcnl1c2VyCg==\"  -p PASSWORD=\"c2VjcmV0Cg==\" -p URL=\"jdbc:\n\u003e mysql://172.30.171.241:3306/querydb\"\u003cbr\u003e\n\n```\n--\u003e Deploying template \"restapijdbc/restapijdbc\" to project restapijdbc\n\n     REST/API JDBC\n     ---------\n     My simple implementation of configurable REST/API service\n\n     * With parameters:\n        * URL string=jdbc:mysql://172.30.171.241:3306/querydb\n        * Database type=mysql\n        * Database user name=cXVlcnl1c2VyCg==\n        * Database Password=c2VjcmV0Cg==\n\n--\u003e Creating resources ...\n    imagestream.image.openshift.io \"restapijdbc\" created\n    secret \"mysql\" created\n    persistentvolumeclaim \"restapijdbc\" created\n    deployment.apps \"restapijdbc\" created\n    service \"restapijdbcn\" created\n    service \"restapijdbc\" created\n--\u003e Success\n    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:\n     'oc expose service/restapijdbcn' \n     'oc expose service/restapijdbc' \n    Run 'oc status' to view your app.\n```\n\nPostgreSQL example\u003cbr\u003e\n\u003e oc new-app --template=restapijdbc -p DB=postgres -p USER=\"cXVlcnl1c2VyCg==\" -p PASSWORD=\"c2VjcmV0Cg==\" -p URL=\"jdbc:\n\u003e postgresql://172.30.181.178:5432/querydb\"\n\n## Copy resource data to persistent volume using the container\u003cbr\u003e\n\n\u003e oc get pods\u003cbr\u003e\n\n```\nNAME                          READY   STATUS    RESTARTS   AGE\nrestapijdbc-b54d54cff-lzj8m    1/1     Running   0          67s\n```\n\nLocal directory is */home/sbartkowski/work/restmysqlmodel/resources/*.\n\n\u003e oc cp /home/sbartkowski/work/restmysqlmodel/resources/ restapijdbc-b54d54cff-lzj8m:/var\u003cbr\u003e\n\nThe command creates the following directory structure in the container.\u003cbr\u003e\n\u003cbr\u003e\n\u003e oc rsh restapijdbc-b54d54cff-lzj8m\n\n```\n$ ls /var/resources/ -ltr\ntotal 4\ndrwxr-xr-x. 2 1000700000 root   32 Nov  6 11:25 python\ndrwxr-xr-x. 5 1000700000 root   49 Nov  6 11:25 resoudir\ndrwxr-xr-x. 2 1000700000 root 4096 Nov  6 11:25 restdir\n```\n\nThe resource data are stored in persistent volume. The container can be recreated without losing the configuration.\nAlso, the resource data can be updated and rebuiding the container is not necessary.\u003cbr\u003e\n\n## Use external database\n\nAssume PosgreSQL instance is deployed outside OpenShift cluster on the host *broth1.fyre.ibm.com*. Service\n*externalname* allows access that database without hardcoding the external hostname.\n\u003cbr\u003e\nCreate service *querydb*\u003cbr\u003e\n\n\u003e oc create svc externalname querydb --external-name broth1.fyre.ibm.com\n\nFix *restapijdbc* deployment and container.\u003cbr\u003e\n\n\u003e oc set env deployment/restapijdbc -e URL=\"jdbc:postgresql://querydb:5432/querydb\"\n\n## Test\n\nAssuming HAProxy node *kist* and port *7999*\u003cbr\u003e\n\n\u003e curl  http://kist:7999/resource?resource=appdata\u003cbr\u003e\n\n```JSON\n{\n  \"appname\" : \"Classic Model\",\n  \"logo\" : \"logo192.png\"\n}\n```\n\n\u003e curl  http://kist:7999/productlines\u003cbr\u003e\n\n```\n{\"res\":[{\"productline\":\"Classic Cars\",\"image\":null,\"htmldescription\":null,\"textdescription\":\"Attention car enthusiasts: Make your wildest car ownership dreams come true. Whether you are looking for classic muscle cars, dream sports cars or movie-inspired miniatures, you will find great choices in this category. These replicas feature superb attention to detail and craftsmanship and offer features such as working steering system, opening forward compartment, opening rear trunk with removable spare wheel, 4-wheel independent spring suspension, and so on. The models range in size from 1:10 to 1:24 scale and include numerous limited edition and several out-of-production vehicles. All models include a certificate of authenticity from their manufacturers and come fully assembled and ready for display in the home or office.\"},{\"productline\":\"Motorcycles\",\"image\":null,\"htmldescription\":null,\"textdescription\":\"Our motorcycles are state of the art replicas \n...................\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislawbartkowski%2Frestapijson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanislawbartkowski%2Frestapijson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislawbartkowski%2Frestapijson/lists"}