Web API – best practice – app assembly and coding

Web API – best practice – app assembly and coding

.

Class or code module Link to example
Configuring the app
Enable ‘root’ controller route in App_Start > WebApiConfig.cs LinkRelationsIntro
RootController.cs coding, to return the available link relations LinkRelationsIntro
Persistent data store connection string in Web.config LinkRelationsIntro
(more may be added here)
Plug-in modules (formatter, handler)
Image formatter sep24images
OAuth message handler (which uses this AuthN+AuthZ app) SecurityUsingOAuth
HTTP OPTIONS handler LinkRelationsIntro
WebApiApplication class (in Global.asax.cs) that initializes these plug-in modules LinkRelationsIntro
(more may be added here)
App domain data model
App domain model classes, related (no data annotations) sep20v1
Above, with data annotations sep24migrations
DbContext class (which is the Entity Framework API) sep20v1
Store initializer class, to create objects with associations sep20v1
Above, uploads byte array (e.g. photo) when creating object sep24images
Typical WebApiApplication class support for the store initializer, in situations that do NOT use Code First Migrations (CampusLocationsEditor)
When using Code First Migrations, store initialization happens in the Configuration class (in its Seed method) sep24migrations
Declaring an enumeration for use in an app domain model class EnumTypes
(more may be added here)
App and business logic
(coming soon)
View models
Link relation classes, in the ViewModels folder LinkRelationsIntro
Classes to support GET and POST methods, with link relations and add-new template LinkRelationsIntro
Guidance on naming view model classes Sep 10 notes
Classes to support PUT method (no link relations) sep20v1 (Program) and sep20v1 (Subject)
AutoMapper definitions (in WebApiApplication class) to support all HTTP methods; including standard to-one and to-many projections sep20v1
(more may be added here)
Repositories
Repo base class sep20v1
Repo for entity that includes nested to-many collection (e.g. Program > Subjects) sep20v1
Repo for entity that includes flattened to-one object (e.g. Subject > Program) sep20v1
Repo for entity that supports an ‘image’ representation sep24images
Validate user input for enum types
(more may be added here)
Controllers, no link relations
Supports all methods – GET, POST, PUT, DELETE (no link relations), including nested to-many collection (e.g. Program > Subjects) sep20v1
Above, including flattened to-one object (Subject > Program) sep20v1
Handles ‘image’ representation, upload (PUT) and delivery (GET) (no link relations) sep24images
(more may be added here)
Controllers, WITH link relations
Supports get-all and get-one requests; includes Links, Collection, Template properties LinkRelationsIntro
Supports add-new, update-existing, and delete requests (CampusLocationsEditor)
“Lookups” controller to deliver the string values of enumerations (CampusLocationsEditor)
(more may be added here)

.

.

.

.

.

.

.

.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: