taroooyan

進捗ブログ

Adventar-APIをつくった

はじめに

最近Goを使い始めて練習がてらAPIを作ってみることにした。 Advent Calendarとは 12月1日から25日まで1日に1つ記事を投稿していくというイベント。 これらの記事を管理するサービスとしてQiitaAdventarがある。

つくったもの

github.com

今回はAdventarのAPIを作った。各カレンダーについての情報を返すもの。 https://adventar-api.appspot.com/

アクセス方法

https://adventar-api.appspot.com/*** ***は http://www.adventar.org/calendars/***

サンプル

www.adventar.org/calendars/1530 www.adventar.org

からデータを取得する場合

https://adventar-api.appspot.com/1530

帰ってくるデータJSON形式で

Is_error: bool,
Title: string,
Url: string,
Creator: string,
Description: string,
Entry_count: int,
Posted_count: int,
Calendars: [
    {
        Date: int,
        User: string,
        Icon: string,
        Comment: string,
        Title: string,
        Url: string,
        Is_entry: bool,
        Is_posted: bool
    },
    ...
]

最後に

GoでのJSONを扱うにはそれように構造体を指定してあげないといけない。コードができて実際に動かそうとGAEでやったが、GAE用にコードを変更する必要があってhttpリクエスト周りの変更が面倒だったり、CirlceCIでのテストもスムーズにできなくて手間取った…… まぁ、とりあえず形にはなってよかった。