Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ASP.NetでAPIを作ってみた
Search
laco
January 22, 2014
Programming
520
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ASP.NetでAPIを作ってみた
C#福岡 第三回勉強会にて
API.Net WebAPIの話
laco
January 22, 2014
Transcript
33 slides
ASP.NetでAPIを作ってみた 2014.01/22 C#福岡 第3回勉強会
About me
らこ Suguru Inatomi Twitter:@laco0416 学生 C#とかJavaとかPythonとか http://lacolaco.net
What ‘s ASP.Net Web API?
One ASP.NET (Scott Hanselman氏のブログより)
Microsoft ASP.NET Web API 現行バージョン: 4.0.30506 マルチプラットフォームのHTTPサービスフレームワーク 2012年8月に誕生したばかりの新しい技術 なんと20日にWeb API
2.1リリース http://blogs.msdn.com/b/webdev/archive/2014/01/20/announcing-the- release-of-asp-net-mvc-5-1-asp-net-web-api-2-1-and-asp-net-web- pages-3-1.aspx
ASP.NET Web API (@ITより)
Let’s make it!
Step-1 Make Project
None
None
Step-2 Make Controller
ModelsController Controller class -> ValuesController API endpoint -> http://lacolaco.net/api/values コントローラ名からURLルーティングを
自動でやってくれる
None
None
これだけですでに実行可能 RESTfulなインタフェースが すでに定義済み いたれりつくせり
メソッド名とHTTPのメソッド が対応しているので 名前の変更はNG 使わないAPIを消すのはOK
Step-3 Receive params
引数無しGet 主にデータストアから 全レコードを返す時など。
引数の規則 ・プリミティブ型はUriから ・それ以外はBodyから ・[FromBody]をつけると プリミティブでもBodyから読む ・[FromUri]をつけると オブジェクトでもUriから読む
Uriパラメータ受け取り ・仮引数名がそのままkeyになる api/samples?id=1 ・引数がidだけの時は api/samples/1と api/samples?id=1 は同じ
None
Bodyパラメータ受け取り ・Bodyから受け取れるのは 1つの引数のみ ・モデルクラスを用意して jsonのオブジェクトを受け取る ことができる
Body { id : 0 , value : “CSharp”} ↓
C# new Sample() { id = 0, value = “CSharp”};
Step-4 Run
None
API仕様のページまで 作ってくれる
My product IT Event API
直近1ヶ月のIT系勉強会を返すAPI 文字列で検索も可能 http://api.lacolaco.net/events?query=福岡
ここで終わりだったんですが
Web API 2.1リリース ASP.Net MVC 5.1とWeb API 2.1が同時に正式リリース。 VS 2013
VS 2013 Update 1へのアプデが必要 VS 2012 ASP.NET and Web Tools 2013.1 for Visual Studio 2012の インストールが必要
Web API 2 : VS2013でのみ利用可能だった ↓ Web API 2.1 :
VS2012でも利用可能に。 Install-Package Microsoft.AspNet.WebApi -Version 5.1.0 ・ Global Error Handling (エラーハンドリングを一箇所にまとめられるようになった) ・ Attribute Routing Improvements (属性によるルーティングの改善?) ・ Help Page Improvements (APIヘルプページの改善) ・ IgnoreRoute Support ・ BSON Media-Type Formatter (BSONオブジェクトに対応) ・ Better Support for Async Filters ・ Query Parsing for the Client Formatting Library (System.Net.Http.Formattingの拡張) まだ詳細を把握できていないので詳しくは原文を参照してください http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21
Thank you for listening
More Decks by laco
See All by laco
Angular2とMVVM
laco0416
5
5.7k
Pub使ってますか?
laco0416
1
1.7k
OSC_F_2013 LT
laco0416
0
160
Other Decks in Programming
See All in Programming
眠らない開発チームの作り方
biwakonbu
0
180
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
360
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
将来の標準フォーマッター?ktfmtを深堀る
t45k
1
250
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1.1k
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
250
Canvas 2D Context Next
petamoriken
0
820
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
710
Beyond Chatbots: Agentic UI with Open Standards @W-JAX 2026, München
manfredsteyer
PRO
0
130
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
530
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
410
The browser strikes back
jonoalderson
0
2k
Designing for humans not robots
tammielis
254
26k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
The Spectacular Lies of Maps
axbom
PRO
1
1.2k
The Cult of Friendly URLs
andyhume
79
7.1k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
660
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.3k
How to Think Like a Performance Engineer
csswizardry
28
3k