Creating an Application from Scratch using .NET Core and Angular — Part 4

  • The model class can have sensitive data that you do not want to return in the API
  • The model class have information that is not necessary to return, so you just must return what is really necessary. This way you will not spend resources with unnecessary processes
Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection
  • Transient — Transient lifetime services (AddTransient) are created each time they’re requested from the service container.
  • Scoped — Scoped lifetime services (AddScoped) are created once per client request (connection).
  • Singleton — Singleton lifetime services (AddSingleton) are created the first time they’re requested.
using AutoMapper;
using BookStore.API.Configuration;
Install-Package Swashbuckle.AspNetCore
using Microsoft.OpenApi.Models;
  • GET — which request a representation of a specific resource. It is used only to return data.
  • POST — which is used to submit an entity to a specific resource. We generally use POST to create a new resource.
  • PUT — which is used to replace all the properties of a resource. We generally use PUT to update a resource.
  • PATCH — which is used to apply partial modifications.
  • DELETE — which is used to delete a resource.
  • 200 — Ok: This status means that the request was successful.
  • 201 — Created: This status means that the request has succeeded and a new resource has been created as a result. This is usually returned after a POST request.
  • 204 — No Content: We can return this status when we do not want to return anything.
  • 400 — BadRequest: This is a generic status for error. It means that the server could not understand the request due to invalid syntax.
  • 401 — Unauthorized: This status means that the client is not authenticated, and he should authenticate to do the request.
  • 403 — Forbidden: This status means that the client is authenticated but he does not have permission to do what he is trying to do. Unlike 401, the client’s identity is known to the server.
  • 404 — Not found: This status means that the server could not find the requested resource.
  • 500 — Internal Server Error: This is a generic answer from REST API, it means that the server has encountered a situation it doesn’t know how to handle.
  • 503 — Service Unavailable: This status means that the server is not ready to handle the request.
https://github.com/henriquesd/BookStore

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store