• Stars
    star
    307
  • Rank 136,109 (Top 3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Get started with KrakenD. A docker compose with KrakenD and a fake api to play with

KrakenD Playground logo

KrakenD Playground

The KrakenD Playground is a demonstration environment that puts together the necessary pieces to get you started with our API Gateway, using example use-cases.

As KrakenD is an API gateway, we have added surrounding services:

  • Internal and third-party services that feed the gateway
  • Authentication/authorization examples, including JWT token-based authentication with Auth0 integration, a JWT token revoker, API-Key-based authentication, and basic authentication.
  • Integrations with Grafana+Influx (metrics), Jaeger (tracing) and RabbitMQ (for async agents).

KrakenD Docker compose

Demo video

Click to play on Youtube (with subtitles)

Services

The docker-compose.yml includes the following services:

The API Gateway!

On port 8080, you have an instance of KrakenD Enterprise Edition with several endpoints. Its configuration is available at config/krakend/krakend.json, including descriptive @comments for each endpoint.

Visit http://localhost:8080/demo/ where you'll find a static website served by KrakenD itself.

Fake API backend (Upstream)

On port 8000, you have a simple fake API that provides raw data to the gateway. You can add or remove data by adding XML, JSON, or RSS files in the data folder.

It runs in http://localhost:8000

Metrics, logs & tracing

KrakenD can export telemetry to several services; this demonstration has a few examples. After starting the service and calling some endpoints, you will see the activity in Jaeger, Grafana, and Kibana.

Metrics Logging Tracing
Grafana shows the metrics stored by KrakenD on InfluxDB Kibana shows the logs registered by Logstash and persisted in Elasticsearch Jaeger shows the traces of the activity between the client and your end services, including times of hops.
URL: http://localhost:4000 URL: http://localhost:5601 URL: http://localhost:16686
grafana screenshot Kibana screenshot jaeger screenshot

NOTE: To import a Kibana dashboard with some valuable metrics, run in the console the following command once all has started:

    $ make elastic

Web client

This consumer of the API gateway is a simple Express JS application that interacts with KrakenD to fetch the data. All code is under images/spa-auth-web/.

The client is a Single Page Application using Auth0 to generate JWT tokens.

You don't need to install any npm locally; the docker image will download and install the dependencies in the container.

Visit http://localhost:3000

The async agent

A RabbitMQ instance is ready to accept AMQP messages to be delivered to the gateway.

You can insert messages in the krakend queue at http://localhost:15672/#/queues/%2F/krakend (credentials: guest/guest) and see how the async agent picks them and delivers them.

Metrics

A Jaeger dashboard shows the traces of the activity you generate. Runs on http://localhost:16686

A Grafana dashboard shows the metrics of the activity you generate. Runs on http://localhost:3003 (credentials: admin/admin)

The JWT revoker

A simple implementation of a JWT revoker using the KrakenD remote bloomfilter client.

More information about JWT revoking is available at https://www.krakend.io/docs/authorization/revoking-tokens/

It runs on http://localhost:9000

Start the service

Only if you want to try the Auth0 integration...

Create a new SPA application in Auth0 and fill the autogenerated values they give you under images/spa-auth-web/auth0-variables.js

var AUTH0_CLIENT_ID='AUTH0_CLIENT_ID';
var AUTH0_DOMAIN='AUTH0_DOMAIN';
var AUTH0_AUDIENCE = 'AUTH0_AUDIENCE';

You must do this before starting the docker-compose. If you have started docker-compose before setting these variables, you must build the image again with docker compose build web.

Running the playground

To start the stack included in docker-compose

    $ make start

To follow the KrakenD logs after the complete stack is up & running

    $ make logs

To shut down the complete stack, removing all the volumes

    $ make stop

Play!

Fire up your browser, curl, postman, httpie, or anything else you like to interact with any published services.

When you change the krakend.json, the changes are applied automatically.

πŸ’‘ Bonus track - Flexible configuration
We've added an example of flexible configuration, so you can view how it works in practice.

Apart from the default config file, krakend.json, you will find a krakend-flexible-config.tmpl that includes some code snippets, invokes a template using variables, and show some basic logic (iterations & conditions).

When working with the flexible configuration, you can optionally ask KrakenD to save the "compiled" output to a file. We've added a command make compile-flexible-config so you can see quickly and easily how KrakenD builds the final configuration file based on the existing templates.

Internally KrakenD's flexible configuration uses Golang templating syntax.

Editing the API Gateway endpoints

To add or remove endpoints, edit the file krakend/krakend.json. The easiest way to do it is by dragging this file to the KrakenD Designer and downloading the edited file. If you move the downloaded file to krakend/krakend.json the server will apply the changes automatically.

To change the data in the static server (simulating your backend API), edit, add or delete files in the data/ folder.

The following endpoints are worth noticing:

Feature Endpoint Description
Simple request /public A simple request calling an internal service and returning a JSON response
Data aggregation and manipulation /git/{user} Aggregating multiple calls concurrently and manipulating some data from GitHub API
Caching backend responses /market/cached Caching a backend response (based on cache headers provided by the backend)
Concurrent requests /market/concurrent Using concurrent requests to gather data from Coingecko API
Sequential calls /sequential Using sequential proxy to build a pipe of sequential calls, using values from 1st call response into 2nd call request
An aggregated requests with a failing backend /fail An example on how the X-KrakenD-complete header works when a backend fails on an aggregated response
JWT based Authentication /private/auth0 Protects and endpoint validating JWT tokens issued by Auth0

You will find more examples with comments in config/krakend/krakend.json

Contribute!

Everyone can get started with KrakenD at this repository.

Try it out! If it doesn't help you, or you think you can add additional endpoints or middleware integrations, please open a pull request! (We may be too used to KrakenD and don't recognize what a starter demo should include.)

Thanks!


If you have any questions or doubts, you can find our support resources at https://www.krakend.io/support/

Interested in a demo or a trial license of KrakenD Enterprise? Write us Β»


Note: if you're looking for the KrakenD Enterprise Edition Playground, you'll find it here: https://github.com/krakendio/playground-enterprise

More Repositories

1

krakend-ce

High-performance, stateless, declarative, API Gateway written in Go.
Go
1,234
star
2

krakendesigner

KrakenD configuration editor.
HTML
86
star
3

bloomfilter

Bloomfilter written in Golang, includes rotation and RPC
Go
76
star
4

krakend-contrib

A list of awesome modules and adaptors for the KrakenD framework.
66
star
5

krakend-jose

Javascript Object Signing and Encryption (JOSE) component for the KrakenD framework
Go
33
star
6

krakend-opencensus

Opencensus adapter. Exports KrakenD metrics and traces to InfluxDB, Prometheus, Zipkin, Jaeger, Xray, StackDriver, Datadog and Logger
Go
27
star
7

krakend-martian

Integrate the martian lib in the KrakenD framework
Go
20
star
8

krakend-postman

Create automatic POSTMAN collection descriptions from you KrakenD config file
Go
20
star
9

krakend-documentation

All the documentation under http://www.krakend.io/docs/
20
star
10

krakend-ratelimit

A collection of curated ratelimiter adaptors for the KrakenD framework
Go
20
star
11

krakend-config2dot

Translate your KrakenD config file into a dot graph
Go
17
star
12

krakend-watch

Allows you to monitor a KrakenD config file for changes and reload the service with the new version.
Shell
13
star
13

krakend-cel

Common Expression Language (CEL) module for the KrakenD framework
Go
12
star
14

krakend-circuitbreaker

A collection of curated circuit breaker adaptors for the KrakenD framework
Go
11
star
15

examples

Lua
11
star
16

krakend-metrics

A set of building blocks for instrumenting KakenD gateways
Go
11
star
17

krakend-cors

Adds CORS support to the KrakenD framework
Go
10
star
18

fpm-docker

Docker image to generate RPM and DEB packages based on fpm
10
star
19

krakend-pubsub

a pubsub backend for the KrakenD framework
Go
10
star
20

flatmap

flatten and expand maps of interfaces
Go
10
star
21

krakend-amqp

AMQP compatible backend for the KrakenD framework
Go
10
star
22

krakend-lambda

consume lambda functions through a KrakenD API Gateway
Go
10
star
23

krakend-grpc

gRPC adapter for the KrakenD framework
Go
9
star
24

krakend-flexibleconfig

Extended features for KrakenD config parsers
Go
9
star
25

krakend-oauth2-clientcredentials

Add support for auth2 client credentials grant to the KrakenD framework
Go
8
star
26

krakend-cobra

An adapter of the cobra lib for the KrakenD framework
Go
7
star
27

krakend-xml

Add support for XML encoding to the KrakenD framework
Go
7
star
28

krakend-lua

a lua interpreter for the KrakenD framework
Go
7
star
29

krakend-httpcache

A cached http client for the KrakenD framework
Go
7
star
30

krakend-httpsecure

A complete http security layer for the KrakenD framework
Go
7
star
31

krakend-gologging

An improved logger for the KrakenD framework
Go
6
star
32

playground-enterprise

KrakenD Enterprise Playground
HTML
5
star
33

krakend-botdetector

A bot detector middleware for the KrakenD framework
Go
4
star
34

krakend-rss

Add support for RSS encoding to the KrakenD framework
Go
4
star
35

krakend-jsonschema

a JSONschema validator for the KrakenD API Gateway
Go
3
star
36

krakend-logstash

A KrakenD log formatter compatible with logstash
Go
3
star
37

krakend-viper

A powerful config parser for the KrakenD framework
Go
3
star
38

docker-library

Docker library for KrakenD images
Shell
2
star
39

krakend-usage

Anonymous usage report module for the KrakenD framework
Go
2
star
40

krakend-gelf

A gelf writer for KrakenD loggers
Go
1
star
41

krakend-config-migrator

KrakenD tool to migrate configurations from one version to another
Go
1
star
42

telemetry-dashboards

An example Kibana Dashboard to visualize graphs based on KrakenD logs
Shell
1
star