A demonstrative HTTP API, which follows REST standards, is basically a kind of photo upload service.
Configure, run, and create a profile to start uploading your favorite photos.
Follow the guide to complete the installation. Upon the successful completion of Setup & Deployment phases, the app will be
accessible from http://localhost:8080. See Endpoints section to learn more about its usage.
Most request bodies can be delivered either as JSON payload
or in x-www-form-urlencoded
format until stated otherwise.
Request body (all fields are required) :
{
"email": "...@...",
"username": "...",
"password": "***"
}
Request body ('password' and " 'username' OR 'email' " are required) :
{
"email": "...@...",
"username": "...",
"password": "***"
}
Retrieves a specific profile by username.
Request body ('photo' is required) :
{
"photo": < multi-part image file > // jpeg (jpg) is currently the only supported format ( < 30 MB )
"tags": < Array[string] >
"description": < string >
}
Retrieves a photo collection by its owner's ID.
Retrieves a specific photo's details by ID.
- Access to an Amazon S3 or S3 compatible (e.g., Backblaze B2) storage service
- Docker (engine >= 18.06.0)
- Git CLI
- Unix-like environment that supports building Makefiles, e.g., MacOS, Linux, Windows Subsystem for Linux, Cygwin
- (Optional) PostgreSQL DBMS >= 10.x (DBaaS or local)
- Open a shell and clone the repository with:
git clone https://github.com/baturalpk/photo-bucket.git
- Change the current directory to the newly created
photo-bucket
directory:
cd photo-bucket
- Create a file named
secrets.yaml
with the same content ofconfig/secrets.template.yaml
underconfig
directory:
cp config/secrets.template.yaml config/secrets.yaml
- (If prerequisite 5 is not ensured) Create a file named
db.env
with the same content ofconfig/db.template.env
underconfig
directory:
cp config/db.template.env config/db.env
- Edit the newly created files
config/secrets.yaml
andconfig/db.env
using the specifications given under Configurations section.
Example:
env: "dev"
es256:
privateKey: |
-----BEGIN EC PRIVATE KEY-----
MHcCy3/TPeoMpGsC7WuUDt4Xvw+nRLRasfasfasfBai3t5ZzUCEQuWoAoGCqGSM49
AwEHoUQDQgAEAQEEIOy+eNKDTo4uOImTK9p2tgv78OGWGD9MWtnuroh6mUqvMHuJc
or/E9SlJ/jS2XWRWrRsZkbEMTzx/Ptf3Jg==
-----END EC PRIVATE KEY-----
publicKey: |
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYsfasfaasfasdgsdagsdfSAFASFASEeoMpGsC7WuUDCSD9
MWto6upWknurXvw+nRLqvMHuJcor/E9SlJ/jS2XWRWrRsZkbEMTzx/Ptf3Jg==
-----END PUBLIC KEY-----
postgresURI:
test: "postgres://<USERNAME>:<PASSWORD>@localhost:5432/photo-bucket-testDB"
dev: "postgres://<USERNAME>:<PASSWORD>@localhost:5432/photo-bucket-devDB"
prod: "postgres://<USERNAME>:<PASSWORD>@pgsql:5432/photo-bucket"
s3:
bucketNames:
photos:
test: "my-photos_test"
dev: "my-photos_dev"
prod: "my-photos"
credentials:
id: "***"
secret: "***"
endpoint: "https://s3.us-west-2.***"
region: "us-west-2"
env:
"prod" | "dev" | "test" (The deployment sets env asprod
by default.)es256:
Firstly, you need to generate private and public Elliptic Curve (ES256) keys to be able to sign JSON Web Tokens. Then paste contents of the key files into the proper fields ofsecrets.yaml
as multi-line strings.
Related section(s) in the following guide would be helpful: https://cloud.google.com/iot/docs/how-tos/credentials/keyspostgresURI:
Postgres connection strings for test, development, and production environments respectively.s3/bucketNames/photos:
S3 bucket names for test, development, and production environments respectively.s3/credentials:
Your ID & API Secret that can be obtained by object storage provider.s3/endpoint
&s3/region:
The S3 protocol compatible endpoint and region values that can be obtained by object storage provider.
Example:
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_DB=photo-bucket
- POSTGRES_USER: Your Postgres username that will be used at the initialization phase.
- POSTGRES_PASSWORD: Your Postgres password that will be used at the initialization phase.
- POSTGRES_DB: Your Postgres database name that will be used at the initialization phase.
- Ensure that you have completed the steps given under Setup section successfully.
- Ensure that the Docker engine is operating healthy.
- Open a shell at the project's root directory (
photo-bucket
). - Run the target
deployment
fromMakefile
with:make deployment
- After a short time, the application will be accessible from:
http://localhost:8080
Optionally you can create binary executables for various OS platforms:
- Ensure that you have completed the steps given under Setup section successfully.
- Open a shell at the project's root directory (
photo-bucket
). - Run the target
darwin_build
fromMakefile
with:make darwin_build
- Upon the successful completion of build process, executable can be found under the newly created
build
directory.
- Ensure that you have completed the steps given under Setup section successfully.
- Open a shell at the project's root directory (
photo-bucket
). - Run the target
linux_build
fromMakefile
with:make linux_build
- Upon the successful completion of build process, executable can be found under the newly created
build
directory.
- Ensure that you have completed the steps given under Setup section successfully.
- Open a shell at the project's root directory (
photo-bucket
). - Run the target
windows_build
fromMakefile
with:make windows_build
- Upon the successful completion of build process, executable can be found under the newly created
build
directory.
Unit tests for repositories
and clients
are available under the relevant directories:
- Repositories:
services/photo/...
&services/profile/...
- Clients:
clients/s3client/...
&clients/postgres/...
&clients/entclient/...
❗ Ensure that you have successfully completed the steps given under Setup section before executing tests.