📜  codewar api (1)

📅  最后修改于: 2023-12-03 14:59:58.443000             🧑  作者: Mango

Codewars API

Codewars API is a RESTful API that allows developers to access codewars.com challenge data. With Codewars API, developers can integrate the challenge data into their applications, create their own clients and interact with Codewars data programmatically.

Endpoints
User:
  • /users/:username

    • Returns data on the user with the provided :username. Includes user information such as username, clan, leaderboard position, honor, skills, and completed challenges.
    • Example response data:
    {
        "username": "user123",
        "clan": "Codewars",
        "leaderboardPosition": 123,
        "honor": 4567,
        "skills": {
            "ruby": {
                "score": 1234,
                "rank": 3
            },
            "javascript": {
                "score": 5678,
                "rank": 2
            }
        },
        "codeChallenges": {
            "totalAuthored": 12,
            "totalCompleted": 89,
            "languages": {
                "ruby": {
                    "authored": 3,
                    "completed": 45
                },
                "javascript": {
                    "authored": 9,
                    "completed": 44
                }
            }
        }
    }
    
  • /users/:username/code-challenges/completed?page=:page&pageSize=:pageSize

    • Returns data on the user's completed code challenges. Allows for pagination and setting a page size.
    • Example response data:
    {
        "page": 1,
        "pageSize": 20,
        "totalPages": 5,
        "totalItems": 100,
        "data": [
            {
                "id": "123456abcdef",
                "name": "Some challenge",
                "slug": "some-challenge",
                "completedAt": "2021-04-01T12:34:56Z",
                "completedLanguages": ["ruby"]
            },
            {
                "id": "7890ghijklmno",
                "name": "Another challenge",
                "slug": "another-challenge",
                "completedAt": "2021-03-31T12:34:56Z",
                "completedLanguages": ["javascript"]
            }
        ]
    }
    
Challenges:
  • /code-challenges/:id

    • Returns data on the challenge with the provided :id. Includes challenge information such as name, description, author, tags, and difficulty.
    • Example response data:
    {
        "name": "Some challenge",
        "slug": "some-challenge",
        "description": "Some description of the challenge.",
        "author": "user123",
        "tags": ["tag1", "tag2"],
        "rank": {
            "id": 123,
            "name": "3 kyu"
        },
        "language": "ruby",
        "framework": "rspec",
        "createdAt": "2021-04-01T12:34:56Z",
        "totalAttempts": 100,
        "totalCompleted": 50
    }
    
  • /code-challenges/:id/solutions

    • Returns data on the solutions submitted for the challenge with the provided :id. Includes information such as author, language, and date submitted.
    • Example response data:
    {
        "page": 1,
        "pageSize": 20,
        "totalPages": 5,
        "totalItems": 100,
        "data": [
            {
                "id": "solution123",
                "author": "user456",
                "language": "ruby",
                "createdAt": "2021-04-02T12:34:56Z",
                "url": "https://www.codewars.com/kata/some-challenge/ruby"
            },
            {
                "id": "solution456",
                "author": "user789",
                "language": "javascript",
                "createdAt": "2021-04-03T12:34:56Z",
                "url": "https://www.codewars.com/kata/some-challenge/javascript"
            }
        ]
    }
    
Authentication

To access the Codewars API, developers must first obtain an API key. This can be done by logging in to codewars.com, navigating to the API Documentation page, and following the instructions provided.

Once obtained, the API key can be included in requests by setting the Authorization header as Bearer <API_KEY>. For example:

Authorization: Bearer 123abc456def