Coder Social home page Coder Social logo

httpclientapp's Introduction

HttpClientApp

This project is a simple example about how use HttpClient in a .NET Core console application. This project is a simple console application that uses the mock API to get and send data. Also this project was builded using good practices about OOP.

How to run

  1. The easier way is open the project in Visual Studio and run it from there.
  2. The console application will run and display the questions and answers from the mocked API.

If you want to run it from the command line, follow the instructions below.

How to run from the command line

  1. Clone the repository and run the following commands in the root directory of the project
  2. dotnet restore
  3. dotnet run
  4. The console application will run and display the questions and answers from the mocked API.

Summary of the keys to serialization

  1. The System.Text.Json.Serialization namespace is used to serialize and deserialize JSON.
  2. Use the JsonSerializer class to serialize and deserialize JSON.
  3. Is importan to use the JsonPropertyName attribute to map the properties of the DTO to the properties of the domain object.
  4. Even it's a good practice use DTO pattern to map the domain object to the provider object and viceversa.
  internal class AnimalDto
  {
    [JsonPropertyName( "name" )]
    public string Name { get; set; }

    [JsonPropertyName( "color" )]
    public string Color { get; set; }

    [JsonPropertyName( "sound" )]
    public string Sound { get; set; }

    [JsonPropertyName( "image" )]
    public Uri Image { get; set; }

    public static AnimalDto FromDomain( Animal animal )
    {
      return new AnimalDto
      {
        Name = animal.Name,
        Color = animal.Color,
        Sound = animal.Sound,
        Image = animal.Image
      };
    }
  }

httpclientapp's People

Contributors

harvic3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.