C# Project Structure — Part5

iOSTom
3 min readOct 18, 2021

It’s been awhile and I have been learning a ton most recently C#. In this article, I will explain how I structured an application that consumes and processes data from multiple open source api’s.

To retrieve data smoothly I use a type specific client to interact with each API. The data is de-serialized using a model class which makes the data easier to work with. The response is passed and displayed using an API controller.

This is how I structured the Application:

The Client Folder is used to store third party web api clients that the application gets data from.

Third party web clients

The reason why I decided to create a client for each web api is because it separates requests into types using a controller action pattern. Following the controller action pattern and taking advantage of named type httpclients made development fast and easy.

The other reason why I like separating each client is because I can preconfigure each client by setting DefaultHeaders in the Startup.cs file

Since I can set a base address and create custom headers in the application configuration, keeps the client clean and easier to read.

Client

When the GetStateJurdictionData method is called:

  1. Creates a new OpenStatesClient
  2. Uses the OpenStatesClient to call the endpoint jurisdictions
  3. Check the response status if successful
  4. The response content are read
  5. The response content are de-serialized using the Jurisdiction model
  6. Returns a list of results

Now that I have a List of Results how do I retrieve the data and what path will the user take to see it?

I decided to create service folder which will store each api service. If there is a client each client will use their corresponding service to expose their data. For example the OpenStatesClient will…

--

--

iOSTom

iOS Developer, Go, Java, C#, Blockchain enthusiast, Data junkie