USE sxapi with docker

You can use sxapi within a container by using our public official sxapi docker image

Want to try ?

To try this application before working on it, the easiest way is to use the container version. Follow theses steps to run a sxapi application within the next couple of minutes. (You can skip the first step if you already have docker installed and running)

1. Install and start docker

Theses command are for a Red Hat Linux like environement (Fedora, CentOS, RHEL, Suse). Please adapt yum command to the apt-get equivalent if you are using a Debian like system (Ubuntu, Debian)

sudo yum install -y docker
sudo service docker start

For more information on how to install and execute a docker runtime, please see the official docker installation guide After installation, pay attention to your user authorisation. Your current user must interact with the docker daemon.

2. Create your working directory

To run you test in a sandbox, you should isolate your sxapi test from your current work by creating a working directory.

mkdir ~/test-sxapi
cd ~/test-sxapi

3. Get the sxapi container image

Use docker command to get sxapi container image from the docker hub registry. This will update your local docker image cache.

docker pull startx/sxapi:latest

4. Create your sxapi.yml configuration file

Create a file named sxapi.yml

vi ~/test-sxapi/sxapi.yml

Edit it with the following content

name: sample-api
description: my sample api using sxapi-core framework
version: 0.0.0
debug: true
log:
  filters:
    level: '0,1,2,3,4'
    type: debug,info,error,warn
server:
  endpoints:
  - path: "/"
    body: "<html><head></head><body><h1>My sample API</h1></body></html>"

You can change name, description, version and server.endpoints.body with personalized content

5. Run your application

with your own configuration file

docker run -d -p 8077:8077 -v ~/test-sxapi/sxapi.yml:/conf/sxapi.yml:ro startx/sxapi

or using environement variable

docker run -d -p 8077:8077  --env SXAPI_CONF=$(cat ~/test-sxapi/sxapi.yml) startx/sxapi

6. Explore your api

Connect to http://localhost:8077/ with your favorite navigator. You should see an html message "My Sample API".

Container with default configuration

  1. Get the last version of sxapi container from docker hub registry
docker pull startx/sxapi:latest
  1. Run your sample application
// run on port 8077 and attach console
docker run startx/sxapi
// or run in detached mode and expose port 81
docker run -d -p 81:8077 startx/sxapi
  1. Connect to http://localhost:8077 or http://localhost:81 with your favorite navigator

Container with your own configuration (docker)

The purpose of sxapi is to help you build your own api microservice. when using our container version, you can follow these step :

  1. Get the last version of sxapi container from docker hub registry
docker pull startx/sxapi:latest
  1. Create a file named sxapi.yml and edit it with the following content
name: sample-api
description: my sample api using sxapi-core framework
version: 0.0.0
debug: true
log:
  filters:
    level: '0,1,2,3,4'
    type: debug,info,error,warn
server:
  endpoints:
  - path: "/"
    body: "<html><head></head><body><h1>My sample API</h1></body></html>"
  1. Run your application
docker run -d -p 8077:8077 -v $(pwd)/sxapi.yml:/conf/sxapi.yml:ro startx/sxapi
  1. Connect to http://localhost:8077 with your favorite navigator

Container with your own configuration (docker-compose)

If you use docker-compose, you can use the following docker-compose.yml sample file

api:
  image: startx/sxapi:latest
  container_name: "my-api"
  ports:
    - "8077:8077"
  volumes:
  - "./sxapi-dev.yml:/conf/sxapi.yml:ro"
  1. Create your docker-compose.yml file with the previous content

  2. Create a file named sxapi.yml and edit it with the following content

name: sample-api
description: my sample api using sxapi-core framework
version: 0.0.0
debug: true
log:
  filters:
    level: '0,1,2,3,4'
    type: debug,info,error,warn
server:
  endpoints:
  - path: "/"
    body: "<html><head></head><body><h1>My sample API</h1></body></html>"
  1. Run your application
docker-compose up
  1. Connect to http://localhost:8077 with your favorite navigator

Using Openshift

If you're familiar with Openshift PaaS, you will find 5 usefull templates to use in your project - statefulSet template with configuration (embeded in template) embeded in a configMap mounted volume - deployConfig template with configuration (template parameter) directly loaded into an environement variable - deployConfig template with configuration (template parameter) embeded in a configMap mounted volume - deployConfig template with configuration (embeded in template) embeded in a configMap mounted volume - deployConfig template with configuration in mounted volume

You can also use various example application use-case templates : - deployConfig template with simple configuration - deployConfig template with bot configuration - deployConfig template with full configuration

For example you can run

oc new-project test
oc create -f https://raw.githubusercontent.com/startxfr/sxapi-core/testing/docs/guides/okd-example-cm_embed.templateed.yml
oc new-app --template sxapi-cm-embeded-template -p APPLICATION_NAME=sxapi-example

You can add them in a project using openshift user guide