cfml24h
cfml24h copied to clipboard
On JSON and CFHTTP
I have this code handy
<form action="index.cfm?action=process" method="post" class="form-inline">
<div class="form-group">
<cfoutput>
<input type="text" name="zip" value="#form.zip#" />
</cfoutput>
</div>
<button type="submit" class="btn btn-primary btn-large">Get Weather</button>
</form>
<cfif url.action EQ "process">
<cfhttp url="http://api.openweathermap.org/data/2.5/weather?zip=#form.zip#,us&appid=#application.openweatherkey#">
<cfset JSONdata = DeserializeJSON(cfhttp.Filecontent)>
<cfoutput>
<h1>Weather for #encodeForHTML(JSONData.name)#</h1>
<blockquote>
<p>Temperature: #DegreesKtoC(JSONData.main.temp)# (Hi: #DegreesKtoC(JSONData.main.temp_max)# / Lo: #DegreesKtoC(JSONData.main.temp_min)#)<p>
<p>Wind: #encodeForHTML(JSONData.wind.speed)# km/h. Clouds: #encodeForHTML(JSONData.clouds.all)#%</p>
<footer>Powered by <a href="http://openweathermap.org/current" target="_blank">OpenWeatherMap</a></footer>
</blockquote>
</cfoutput>
<cfdump var="#JSONData#" expand="no">
</cfif>
I am thinking of working this up for either JSON or CFHTTP. It is just there is a lot support code in this. I am wondering if a different approach is in order