Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9134

モックサーバ(instant-mock)で送信できるContent-Typeメモ

$
0
0
モックサーバ(instant-mock)で送信できるContent-Typeメモ 前回下記の記事でinstant-mockの構築手順を(ほぼ自分用に)まとめた。 今回はこのモックサーバーはresponse bodyにどんなデータの形式を入れ込んで送信できるのかを検証してみた。 検証結果 bodyに入れ込むことができたデータの形式は以下のものであった。 JSONファイル PDFファイル EXCELファイル( .xlsx OFFICE 2007以降) CSVファイル HTMLファイル CSSファイル テキストファイル JPEGファイル(.jpg) PNGファイル Bitmapファイル bodyにデータを格納する際にContent-Typeの参考にさせていただいたのは下記サイトである。 ymlファイル APIを定義したymlファイルか下記通り。 mockサーバを初期化した際にできたymlファイルに書き加えていった。 parser-default.yml - if: query: group: team-a then: status: 200 headers: Content-Type: application/json body: team-a.json - if: query: group: team-b then: status: 200 headers: Content-Type: application/json body: team-b.json - if: query: group: team-pdf then: status: 200 headers: Content-Type: application/pdf body: PDFファイルだお.pdf - if: query: group: team-sheet then: status: 200 headers: Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet body: test.xlsx - if: query: group: team-csv then: status: 200 headers: Content-Type: text/csv body: hell.csv - if: query: group: team-html then: status: 200 headers: Content-Type: text/html body: test.html - if: query: group: team-css then: status: 200 headers: Content-Type: text/css body: test.css - if: query: group: team-text then: status: 200 headers: Content-Type: text/plain body: hello.txt - if: query: group: team-jpeg then: status: 200 headers: Content-Type: image/jpeg body: テスト.jpg - if: query: group: team-png then: status: 200 headers: Content-Type: image/png body: テスト.png - if: query: group: team-bmp then: status: 200 headers: Content-Type: image/bmp body: テスト.bmp - then: status: 200 headers: Content-Type: application/json body: all.json 実行結果 ARC(Advanced REST client)を使って定義したAPIのレスポンスを確認しようとしたところ、 レスポンス結果がバイナリーコードのまま表示され、上手く送れてるのかの判別がしにくかった。 ARCのスクショ そこで今回はコンソールでgetコマンドを使用して動作検証を行った。 JSONファイル ※team-aとteam-bはmockサーバを初期化した際にできたymlファイルに元々記載してあったもの。 http://localhost:3000/mock/bodyTest?group=team-a team-aスクショ http://localhost:3000/mock/bodyTest?group=team-b team-bスクショ PDFファイル http://localhost:3000/mock/bodyTest?group=team-pdf team-pdfスクショ EXCELファイル( .xlsx OFFICE 2007以降) ブラウザの画面の表示はymlファイルの一番最後に記述してあるthenのjsonファイルの中身が表示された。 http://localhost:3000/mock/bodyTest?group=team-sheet team-sheetスクショ CSVファイル http://localhost:3000/mock/bodyTest?group=team-csv team-csvスクショteam-csv HTMLファイル http://localhost:3000/mock/bodyTest?group=team-html team-htmlスクショ CSSファイル http://localhost:3000/mock/bodyTest?group=team-css team-cssスクショ テキストファイル http://localhost:3000/mock/bodyTest?group=team-text team-textスクショ JPEGファイル(.jpg) http://localhost:3000/mock/bodyTest?group=team-jpeg team-jpegスクショ PNGファイル http://localhost:3000/mock/bodyTest?group=team-png team-pngスクショ Bitmapファイル http://localhost:3000/mock/bodyTest?group=team-bmp team-bmpスクショ 以上が試した結果になる。 もし気が向いたら他のContent-Typeも試して追記するカモ。。。

Viewing all articles
Browse latest Browse all 9134

Trending Articles