You know you have to have a great experience when you develop your iOS, android and Windows Phone applications right? The greatest experience you can give your users is around their data.
4. Agenda
The Top Reasons You Need to Learn about Data in Your Windows Phone App
://
HTTP
1 UNDERSTAND HTTP
PROTOCOL
WEB
SERVICES
2 UNDERSTAND WEB SERVICES
REST
3 UNDERSTAND REST
DATA
CACHING
4 KNOW HOW TO CACHE DATA
IN THE APP
MVVM
5 PICK AND USE A GOOD MVVM
FRAMEWORK
DATA
VIZ
6 LEARN HOW TO SHOW
DATA IN YOUR APP
7. WHAT SHOULD YOU KNOW ABOUT HTTP?
Resources
These are the URLs you use to get to pages on the
web
Request Headers
These are additional instructions that are sent with the
request. These might define what type of response is
required or authorization details.
Request Verbs
These describe what you want to do with the resource.
A browser typically issues a GET verb to instruct the
endpoint it wants to get data, however there are many
other verbs available including things like POST, PUT
and DELETE.
Request Body
Data that is sent with the request. For example a
POST (creation of a new item) will required some data
which is typically sent as the request body in the format
of JSON or XML.
Response Body
This is the main body of the response. If the request
was to a web server, this might be a full HTML page.
Response Status codes
These codes are issues with the response and give
the client details on the status of the request.
The Top Reasons You Need to Learn about Data in Your Windows Phone App
8. HOW DOES HTTP WORK?
GET CODEMASH.COM
http://www.codemash.com/index.html
WHAT DOES THE BROWSER DO?
GET /index.html HTTP/1.0
From: cwoodruff@live.com
User-Agent: HTTPTool/1.0
[blank line here]
WHAT IS THE RESPONSE?
HTTP/1.0 200 OK
Date: Thu, 8 Jan 2015 3:30:00 GMT
Content-Type: text/html
Content-Length: 1354
<html>
<body>
</body>
</html>
The Top Reasons You Need to Learn about Data in Your Windows Phone App
9. HTTP VERBS
GET
Requests a representation of the specified
Requests using GET should only retrieve
have no other effect.
HEAD
Asks for the response identical to the one
that would correspond to a GET request,
but without the response body.
POST
Requests that the server accept the entity
enclosed in the request as a new
subordinate of the web resource identified
by the URI.
PUT
Requests that the enclosed entity be stored
under the supplied URI.
DELETE
Deletes the specified resource.
PATCH
Applies partial modifications to a resource
The Top Reasons You Need to Learn about Data in Your Windows Phone App
TRACE
Echoes back the received request so that a
client can see what (if any) changes or
additions have been made by intermediate
servers.
OPTIONS
Returns the HTTP methods that the server
supports for the specified URL.
10. HTTP RESONSE CODES
1XX
Request received, continuing process.
This class of status code indicates a
consisting only of the Status-Line and
and is terminated by an empty line.
2XX
This class of status codes indicates the
action requested by the client was received,
understood, accepted and processed
successfully.
3XX
This class of status code indicates the client
must take additional action to complete the
request.
4XX
The 4xx class of status code is intended for
cases in which the client seems to have
errored.
5XX
The server failed to fulfill an apparently
valid request.
Response status codes beginning with the
digit "5" indicate cases in which the server
is aware that it has encountered an error or
is otherwise incapable of performing the
request.
The Top Reasons You Need to Learn about Data in Your Windows Phone App
11. COMMON HTTP RESONSE CODES
The Top Reasons You Need to Learn about Data in Your Windows Phone App
101 Switching Protocols - Tells the
client that the server will switch protocols
to that specified in the Upgrade message
header field during the current
connection. For example, when
requesting a page, a browser might
receive a status code of 101, followed by
an "Upgrade" header showing that the
server is changing to a different version of
HTTP.
200 OK - The request sent by the client
was successful.
202 Accepted - The request has been
accepted for processing, but has not yet
been processed.
204 No Content - The request was
successful but does not require the return
of an entity-body.
301 Moved Permanently - The resource
has permanently moved to a different
URI.
302 Found - The requested resource has
been found under a different URI but the
client should continue to use the original
URI.
303 See Other - The requested response
is at a different URI and should be
accessed using a GET command at the
given URI.
304 Not Modified - The resource has not
been modified since the last request.
12. COMMON HTTP RESONSE CODES
The Top Reasons You Need to Learn about Data in Your Windows Phone App
400 Bad Request - The syntax of the
request was not understood by the server.
401 Not Authorized - The request needs
user authentication.
403 Forbidden - The server has refused
to fulfill the request.
404 Not Found - The document/file
requested by the client was not found.
405 Method Not Allowed - The method
specified in the Request-Line is not
allowed for the specified resource.
407 Proxy Authentication Required -
The request first requires authentication
with the proxy.
500 Internal Server Error - The request
was unsuccessful due to an unexpected
condition encountered by the server.
502 Bad Gateway - The server received
an invalid response from the upstream
server while trying to fulfill the request.
503 Service Unavailable - The request
was unsuccessful due to the server being
down or overloaded.
504 Gateway Timeout - The upstream
server failed to send a request in the time
allowed by the server.
14. Types of Web Services
01
02
04
03
Simple Object Access protocol (SOAP)
Representational State Transfer (REST)
Remote Procedure Call (RPC)
Calls over HTTP
The Top Reasons You Need to Learn about Data in Your Windows Phone App
15. EVOLUTION OF WEB SERVICES?
The Top Reasons You Need to Learn about Data in Your Windows Phone App
19. WHAT SHOULD YOU KNOW ABOUT REST?
Resources
REST uses addressable resources to define the
structure of the API. These are the URLs you use to
get to pages on the web
Request Headers
These are additional instructions that are sent with the
request. These might define what type of response is
required or authorization details.
Request Verbs
These describe what you want to do with the resource.
A browser typically issues a GET verb to instruct the
endpoint it wants to get data, however there are many
other verbs available including things like POST, PUT
and DELETE.
Request Body
Data that is sent with the request. For example a
POST (creation of a new item) will required some data
which is typically sent as the request body in the format
of JSON or XML.
Response Body
This is the main body of the response. If the request
was to a web server, this might be a full HTML page, if
it was to an API, this might be a JSON or XML
document.
Response Status codes
These codes are issues with the response and give
the client details on the status of the request.
The Top Reasons You Need to Learn about Data in Your Windows Phone App
20. REST & HTTP VERBS
GET
Requests a representation of the specified
Requests using GET should only retrieve
have no other effect.
POST
Requests that the server accept the entity
enclosed in the request as a new
subordinate of the web resource identified
by the URI.
PUT
Requests that the enclosed entity be stored
under the supplied URI.
DELETE
Deletes the specified resource.
The Top Reasons You Need to Learn about Data in Your Windows Phone App
21. EXAMPLES OF REST
/Products
RESOURCE EXPECTED OUTCOMEVERB RESPONSE CODE
/Products?Color=green
/Products
/Products/81
/Products/881
/Products/81
/Products/81
GET
GET
POST
GET
GET
PUT
DELETE
A list of all products in the system
A list of all products in the system
where the color is red
Creation of a new product
Product with an ID of 81
Some error message
Update of the product with ID of 81
Deletion of the product with ID of
81
200/OK
200/OK
201/Created
200/OK
404/Not Found
204/No Content
204/No Content
The Top Reasons You Need to Learn about Data in Your Windows Phone App
22. SWAGGER UI
The Top Reasons You Need to Learn about Data in Your Windows Phone App
BENEFITS
GENERATE CLIENT CODE BASED ON YOUR
SWAGGER
KEEPS YOUR API FULLY DOCUMENTED
UNDERSTAND REST API QUICKLY
UPDATED WHEN YOU BUILD YOUR API
23.
24.
25. Testing REST Web Services
The Top Reasons You Need to Learn about Data in Your Windows Phone App
BROWSER
DEVELOPER
EXTENSIONS
Web-based REST/Web Services Clients
FIDDLER
Free web debugging tool which logs all
HTTP(S) traffic between your computer
and the Internet.
LINQPAD
Interactively query SQL databases
(among other data sources such as OData
or WCF Data Services) using LINQ, as
well as interactively writing C# code
without the need for an IDE.
SoapUI
SoapUI is an open-source web service
testing application for service-oriented
architectures (SOA) and representational
state transfers (REST). Its functionality
covers web service inspection, invoking,
development, simulation and mocking,
functional testing, load and compliance
testing.
26. DEMO
The Top Reasons You Need to Learn about Data in Your Windows Phone App
http://baseball-stats.info/api/Teams
27. KNOW HOW TO CACHE DATA
IN THE APP
The Top Reasons You Need to Learn about Data in Your Windows Phone App
28. 01
02
04
03
LOCAL
Data that exists on the current device
backed up in the cloud.
APP DATA STORAGE
The Top Reasons You Need to Learn about Data in Your Windows Phone App
LOCALCACHE
Persistent data that exists only on
the current device.
ROAMING
Data that exists on all devices on
which the user has installed the app.
TEMPORARY
Data that could be removed by the
system at any time.
29. DATA TYPES FOR CACHING
UInt8, Int16, UInt16, Int32,
UInt32, Int64, UInt64, Single,
Double
Boolean
Char16, String DateTime, TimeSpan
GUID, Point, Size, Rect ApplicationDataCompositeValue
The Top Reasons You Need to Learn about Data in Your Windows Phone App
Note that there is no binary type. If you need to store binary
data, use an app file
30. EXAMPLES OF DATA CACHING
LOCALSETTINGS
The Top Reasons You Need to Learn about Data in Your Windows Phone App
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["exampleSetting"] = "Hello Windows";
Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
composite["intVal"] = 1;
composite["strVal"] = "string";
localSettings.Values["exampleCompositeSetting"] = composite;
Object value = localSettings.Values["exampleSetting"];
Windows.Storage.ApplicationDataCompositeValue composite =
(Windows.Storage.ApplicationDataCompositeValue)localSettings.Values["exampleCompositeSetting"];
localSettings.Values.Remove("exampleSetting");
31. EXAMPLES OF DATA CACHING
LOCALFOLDER
The Top Reasons You Need to Learn about Data in Your Windows Phone App
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatter =
new Windows.Globalization.DatetimeFormatting.DateTimeFormatter("longtime");
StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt",
CreateCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(sampleFile, formatter.Format(DateTime.Now));
StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt");
String timestamp = await FileIO.ReadTextAsync(sampleFile);
32. EXAMPLES OF DATA CACHING
The Top Reasons You Need to Learn about Data in Your Windows Phone App
TEMPORARYFOLDER
Windows.Storage.StorageFolder temporaryFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatter =
new Windows.Globalization.DatetimeFormatting.DateTimeFormatter("longtime");
StorageFile sampleFile = await temporaryFolder.CreateFileAsync("dataFile.txt",
CreateCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(sampleFile, formatter.Format(DateTime.Now));
StorageFile sampleFile = await temporaryFolder.GetFileAsync("dataFile.txt");
String timestamp = await FileIO.ReadTextAsync(sampleFile);
33. EXAMPLES OF DATA CACHING
The Top Reasons You Need to Learn about Data in Your Windows Phone App
void InitHandlers()
{
Windows.Storage.ApplicationData.Current.DataChanged +=
new TypedEventHandler<ApplicationData, object>(DataChangeHandler);
}
void DataChangeHandler(Windows.Storage.ApplicationData appData, object o)
{
// Refresh your data
}
ROAMINGFOLDER
34. SQL AND NOSQL DATA SOLUTIONS
SQLite
A relational database management system contained in a C
contrast to other database management systems, SQLite is not
separate process that a client program running in another
is part of the using program.
The Top Reasons You Need to Learn about Data in Your Windows Phone App
35. PICK AND USE A GOOD MVVM
FRAMEWORK
The Top Reasons You Need to Learn about Data in Your Windows Phone App
36. BEAUTY OF MVVM
The Top Reasons You Need to Learn about Data in Your Windows Phone App
MODEL VIEWVIEW MODEL
200 OK -- Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.
201 Created -- The request has been fulfilled and resulted in a new resource being created.
204 No Content -- The server successfully processed the request, but is not returning any content. Usually used as a response to a successful delete request.
404 Not Found -- The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.
http://petstore.swagger.io/#/
http://editor.swagger.io/#/
LocalFolder – a local folder, used for storing application data, it’s persistent across application updates and gets backed up to the cloud. This folder was already available in Windows Phone 8 and it’s the same folder as Isolated Storage known from Windows Phone 7.
TemporaryFolder – also a local folder, but its space is managed by the OS. Whenever the system detects it’s running low on storage space, it will start deleting files in temporary so don’t ever strongly depend on files stored in this folder. It makes a perfect place for storing cached web responses or images that can be recreated any time. This folder does not participate in backups.
RoamingFolder – files, stored in this folder, will roam across devices, meaning those files will be synchronized over the cloud whenever possible. Perfect for settings and/or small chunks of state (i.e. for continuous clients). When roaming is disabled on the device, those files (and settings) will get backed up as well. The storage space is limited to 100kB – if application goes over that quota, the synchronization stops (until the total usage falls back under roaming storage quota).
Windows.Storage.ApplicationDataCompositeValue -- Represents related app settings that must be serialized and deserialized atomically.