DEV Community

Cover image for Gophorem - A go API client for forem
Shiraaz Moollatjie
Shiraaz Moollatjie

Posted on

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!!

Top comments (7)

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

Neat! You should cross-post this to forem.dev, others might be inspired by what you did on this project.

Collapse
 
ben profile image
Ben Halpern

Agreed.

Cross-posting between multiple forems as a feature should also eventually be a thing. :)

Collapse
 
shiraazm profile image
Shiraaz Moollatjie

Didn't know how to crosspost between forems, but copy pasta style crosspost is at

forem.dev/shiraazmoollatjie/gophor...

Collapse
 
ben profile image
Ben Halpern

This is great!

Collapse
 
rhymes profile image
rhymes

Well done Shiraaz!

Collapse
 
andrewbaisden profile image
Andrew Baisden

Very cool going to be learning go at some point so nice to see some working projects.

Collapse
 
shiraazm profile image
Shiraaz Moollatjie

You should contribute or use the package!! It's awesome!