Skip to main content

Overview

This endpoint demonstrates KrakenD’s powerful aggregation and transformation capabilities by combining data from multiple GitHub API endpoints into a single response. HTTP Method: GET
Endpoint: /git/{user}

Parameters

user
string
required
The GitHub username to fetch data for (e.g., “octocat”)

What It Demonstrates

  • Aggregation: Combines data from two separate GitHub API calls
  • Field Filtering: Uses allow to return only specific fields
  • Field Mapping: Renames fields (e.g., blogwebsite)
  • Grouping: Organizes user profile data under a user object
  • Collection Handling: Properly handles the repositories array

Request Example

curl http://localhost:8080/git/octocat

Expected Response

{
  "user": {
    "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4",
    "name": "The Octocat",
    "company": "@github",
    "website": "https://github.blog",
    "location": "San Francisco",
    "mail": null,
    "hireable": null,
    "followers": 5000,
    "public_repos": 8,
    "public_gists": 8
  },
  "repos": [
    {
      "id": 1296269,
      "name": "Hello-World",
      "full_name": "octocat/Hello-World",
      "description": "My first repository on GitHub!",
      "stargazers_count": 1500,
      "language": "JavaScript"
    }
  ]
}

Backend Services Called

1. GitHub User Profile

  • Host: https://api.github.com
  • URL Pattern: /users/{user}
  • Purpose: Fetches user profile information
  • Group: user
Allowed Fields:
  • avatar_url
  • name
  • company
  • blog (mapped to website)
  • location
  • mail
  • hireable
  • followers
  • public_repos
  • public_gists

2. GitHub User Repositories

  • Host: https://api.github.com
  • URL Pattern: /users/{user}/repos
  • Purpose: Fetches user’s public repositories
  • Collection: Mapped to repos field

KrakenD Configuration

{
  "@comment": "Feature: Aggregation + Basic transformation (filtering & mapping) + grouping",
  "endpoint": "/git/{user}",
  "backend": [
    {
      "host": ["https://api.github.com"],
      "url_pattern": "/users/{user}",
      "allow": [
        "avatar_url",
        "name",
        "company",
        "blog",
        "location",
        "mail",
        "hireable",
        "followers",
        "public_repos",
        "public_gists"
      ],
      "mapping": {
        "blog": "website"
      },
      "group": "user"
    },
    {
      "host": ["https://api.github.com"],
      "url_pattern": "/users/{user}/repos",
      "mapping": {
        "collection": "repos"
      },
      "is_collection": true
    }
  ]
}

Key Configuration Options

allow

Filters the backend response to include only the specified fields. This reduces payload size and prevents exposing unnecessary data.

mapping

Transforms field names in the response. In this example, GitHub’s blog field becomes website in the API response.

group

Nests the backend response under a specific key. The user profile data is grouped under user to organize the aggregated response.

is_collection

Indicates that the backend returns an array. Combined with mapping, this properly handles the repositories collection.

Use Cases

  • Developer portfolio APIs
  • GitHub integration dashboards
  • User profile aggregation services
  • Simplified GitHub API wrapper

Build docs developers (and LLMs) love