leetcode-api

module
v0.0.0-...-b5b5963 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2024 License: MIT

README ΒΆ

LeetCode REST API Wrapper (LRAW) πŸš€

Description πŸ“

LRAW is a Go-based REST API that simplifies access to LeetCode user data. It wraps LeetCode's GraphQL API, providing an easy-to-use REST interface for developers.

Features ✨

  • Fetch user information by username
  • Simple REST API endpoints
  • Dockerized for easy deployment
  • Modular codebase structure

Why this project? πŸ€“

Problem πŸ€”

Another day I was making a platform for LeetCode users, but I realized there's no official API from LeetCode. Some people have made their own ways to do this, but I didn't really like them. LeetCode is nice, but it does not have a REST API (which is easy to use for the majority). It provides GraphQL, but not everyone is familiar with it, and LeetCode does not officially provide a schema even for that GraphQL. This lack of documentation and the complexity of GraphQL can be a significant hurdle for many developers who want to build applications using LeetCode data.

Solution πŸ’‘

To fix this, I made this project. I like using Go, so I wrote it in Go. I spent some time figuring out how to get data from LeetCode, and I found the right GraphQL queries to use.

This project changes those hard-to-use GraphQL queries into a simple REST API. Now, developers can easily get all the info about any LeetCode user by just making a simple request with the username. This makes it much easier to use LeetCode data in other apps, even if you don't know how to use GraphQL.

Installation πŸ› οΈ

  1. Clone the repository
git clone https://github.com/mutasim77/leetcode-api.git
  1. Navigate to the project directory
cd leetcode-api
  1. Install dependencies
go mod tidy

Usage πŸ–₯️

Running locally 🐌
  1. Start the server
go run cmd/server/main.go
  1. Make a GET request to http://localhost:8080/user/{username}

[!TIP] By default, the server runs on port 8080. You can change this by setting the PORT environment variable:

PORT=3000 go run cmd/server/main.go

This would start the server on port 3000.

Using Docker 🐳
  1. Build the Docker image
docker build -t leetcode-api .
  1. Run the container
docker run -p 8080:8080 leetcode-api

API Endpoints πŸ›£οΈ

  • GET /user/{username}: Fetch user information

Development πŸ’»

  • To run tests:
go test ./test
  • To build the binary:
go build -o leet-api cmd/server/main.go

Deployment 🌐

LRAW can be easily deployed on platforms like:

  • Google Cloud Run
  • AWS ECS (Elastic Container Service)
  • Heroku (with container runtime)
  • DigitalOcean App Platform

Refer to each platform's documentation for specific deployment instructions.

License πŸ“„

This project is MIT licensed.

Directories ΒΆ

Path Synopsis
cmd
server command
internal
api
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL