Gophorem - A go API client for forem

shiraazm

Shiraaz Moollatjie

Posted on August 17, 2020

Gophorem - A go API client for forem

This is a post about gophorem. Where gophers and forem meet to build communities.

I love to use go and I love the idea of forem. I also noticed that forem
does not have any go client support. So I wrote one and it's called gophorem. It's awesome.

GitHub logo ShiraazMoollatjie / gophorem

Where gophers and forem meet to build communities

🤔 What is gophorem

In reality, it's a REST API client for the entire forem API written in go. I
prefer to call it the place where gophers and forem meet up to build communities.

🤷 What can you do with it?

Many things! Soon I'll be posting about how I used gophorem to do some data
visualization with dev.to data. Essentially, the entire forem API is supported
by gophorem
. This means that you can:

  • Use this on ANY forem
  • Manage articles
  • Manage listings
  • Manage webhooks
  • List podcasts, video articles

⌨️ How do you use it?

Gophorem is pretty simple to use. There are also examples to help you get started too.
This is an example to retrieve the latest go articles:

func main() {
    cl := gophorem.NewDevtoClient(gophorem.WithAPIKey("MY_API_KEY"))
    ctx := context.Background()

    // Retrieve all the go articles.
    al, err := cl.Articles(ctx, gophorem.Arguments{
        "tag": "go",
    })
    if err != nil {
        log.Fatalf("something went wrong: %+v", err)
    }

    fmt.Printf("All Articles: %+v", al)
}

🌧️ It supports streaming too!

It's also possible to stream articles with this package. This makes it
useful for certain use cases. It's still a work in progress, but the idea is
to support all the listing endpoints as streams.

This is an example (ripped from the examples folder) of how to stream all the recent go articles on dev.to:

func main() {
    cl := gophorem.NewDevtoClient(gophorem.WithAPIKey("MY_API_KEY"))
    ctx := context.Background()

    s := streamer.NewStreamer(cl)

    ch := s.Articles(ctx, gophorem.Arguments{
        "state": "fresh",
    })

    for a := range ch {
        fmt.Printf("Received article ID: %d, Title: %s, Username: %s URL: %s \n", a.ID, a.Title, a.User.Username, a.URL)
    }
}

🤖 Future work and contributions

Since the API is largely complete, I was thinking of adding the following features:

  • Finalize the streaming features
  • Some rate-limiting features when querying forem servers
  • Support oauth authentication
  • Some showcase articles for what you're able to do. There is a lot of potential in this package

That's all for now, check out the package and have a go at it. All contributions are welcome. Have fun!!

💖 💪 🙅 🚩
shiraazm
Shiraaz Moollatjie

Posted on August 17, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related