REST

A 7-post collection

Polishing Your Curl Expertise

Previous post covers bare minimum of curl you need to know for testing RESTful microservices. Read it first if you need basics. This writing focuses on corner cases and advanced options, making curl experience more enjoyable.

Microservice for experiments

For demonstrations, I've created a simple RESTful microservice in Golang. Use it if you have nothing to experiment with.

package main

import (  
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
)

type RequestSummary struct {  
    URL     string
    Method  string
    Headers http.Header
    Params  url.Values
    Auth    string
    Body    string
}

func main() {  
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        bytes, err
Read more »

Using Curl For Ad Hoc Testing Of RESTful Microservices

curl

There are plenty of tools available for testing RESTful microservices today. Most of them, e.g. SoapUI, are comprehensive solutions and best fit for creating testing suites. Using such a tool to check a single faulty endpoint would be an overkill.

So what should you choose for ad hoc testing instead? There are simplified GUI tools, e.g. Postman, and many developers are happy with them. But if you are after ultimate performance and love command line, there is a better option - curl. In this post I'll show how to check RESTful endpoints using curl with a lot of

Read more »

How To Design Practical RESTful API

There are lots of posts on the Internet on how to design RESTful API already, so why to bother with writing another one? Unfortunately many posts are rather theoretical. They carelessly mix important and unimportant for practice stuff together, sometimes flavouring the mix with questionable recommendations.

It's not easy to find a good practical article on the topic, and Best Practices for Designing a Pragmatic RESTful API by Vinay Sahni is one of these rare pearls. Vinay's post is a comprehensive lengthy chunk and, if you have time, I highly recommend it. If you are after a shorter summary of

Read more »

How To Build Microservice With MongoDB In Golang

These days Golang grows in popularity for writing RESTful microservices. Quite often these services utilize MongoDB as persistence storage. In this post we will build a simple book store microservice using both Go and MongoDB. We will connect to MongoDB with mgo driver and use curl to test the microservice.

MongoDB

MongoDB took market with storm by its simplicity, high availability and document orientation. The advantages of using documents over relational tables are:

  • Documents correspond to native data types in many programming languages.
  • Embedded documents and arrays reduce need for expensive joins.
  • Dynamic schema supports fluent polymorphism.
What is a
Read more »

RESTful web service in Go using Goji

Although net/http provides all necessary abstractions to create web services out of the box, there are alternative packages providing additional features and allowing to minimize boilerplate code. Today we will have a look at how to implement a web service with Goji.

Example of Goji web service

Let's start with a working example. You can get if from GitHub.

package main

import (  
        "encoding/json"
        "fmt"
        "net/http"

        "goji.io"
        "goji.io/pat"
        "golang.org/x/net/context"
)

type book struct {  
        ISBN    string "json:isbn"
        Title   string "json:name"
        Authors string "json:author"
        Price   string "json:price"
}

var bookStore = []book{
Read more »