DEV Community

Victor Avelar
Victor Avelar

Posted on

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.

Top comments (0)