DEV Community

Victor Avelar
Victor Avelar

Posted on

2 1

Episode 5 - Adding resources to your Client

So after being at the Alps for some days, here we go again.

What is a resource?

According to https://restful-api-design.readthedocs.io a resource is described as follows:

The fundamental concept in any RESTful API is the resource. A resource is an object with a type, associated data, relationships to other resources, and a set of methods that operate on it. It is similar to an object instance in an object-oriented programming language, with the important difference that only a few standard methods are defined for the resource (corresponding to the standard HTTP GET, POST, PUT and DELETE methods), while an object instance typically has many methods.

This means that when adding a resource this will allow us to perform operations with our client on specific and well defined types.

How to add a resource to a client?

  1. We create a resource type to hold the methods to interact with articles, this will contain a pointer to our devto.Client implementation,
// articles.go

type ArticleResource struct{
    API *Client // this will receive a pointer to your client instance
}
Enter fullscreen mode Exit fullscreen mode

And then we attach this using the client constructor

you can see a working example in the repository

GitHub logo VictorAvelar / devto-api-go

A go client for the dev.to API

devto-api-go

A go client for the dev.to API

License: MIT

Travis CI

Build Status

Scrutinizer

Scrutinizer Build Status Scrutinizer Code Quality Code Coverage

Go ecosystem

Go Report Card GoDoc

Roadmap

  • Base client and configuration
  • Articles resource
  • CLI utility
  • Authentication resource
  • Extend the tests suite
  • Provide code examples

Disclaimer

This library is not an official dev.to API library, but a friendly contribution to the dev.to community

From now on, we are up for the wtfutil part.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay