Giter VIP home page Giter VIP logo

hands-on-restful-web-services-with-asp.net-core-3's Introduction

Hands-On RESTful Web Services with ASP.NET Core

This is the code repository for Hands-On RESTful Web Services with ASP.NET Core, published by Packt.

Design production-ready, testable, and flexible RESTful APIs for web applications and microservices

What is this book about?

RESTful Web Services with ASP.NET Core is a hands-on guide that will get you familiar with the ASP.NET Core ecosystem and help you in building scalable and maintainable web services with all the latest features. The book will prepare you with an advanced approach while building real-world applications in business and enterprise solutions.

This book covers the following exciting features:

  • Gain a comprehensive working knowledge of ASP.NET Core
  • Integrate third-party tools and frameworks to build maintainable and efficient services
  • Implement patterns using dependency injection to reduce boilerplate code and improve flexibility
  • Use ASP.NET Core's out-of-the-box tools to test your applications
  • Use Docker to run your ASP.NET Core web service in an isolated and self-contained environment
  • Secure your information using HTTPS and token-based authentication
  • Integrate multiple web services using resiliency patterns and messaging techniques

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Build status

Chapter Build status
Chapter 8 Build Status
Chapter 9 Build Status
Chapter 10 Build Status
Chapter 11 Build Status
Chapter 12 Build Status
Chapter 13 Build Status
Chapter 15 Build Status
Chapter 16 Build Status
Chapter 17 Build Status
Chapter 18 Build Status
Chapter 19 Build Status

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
</PropertyGroup>
</Project>

Following is what you need for this book: This book is for anyone who wants to learn how to build RESTful web services with the ASP.NET Core framework to improve the scalability and performance of their applications. Basic knowledge of C# and .NET Core will help you make the best use of the code samples included in the book.

With the following software and hardware list you can run all code files present in the book (Chapter 1-20).

Software and Hardware List

Chapter Software required OS required
1-20 Visual Studio Code(*) Windows, Mac OS X, and Linux (Any)

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Code in Action

To see the Code in Action please visit the following link: http://bit.ly/2Ndao78.

Errata

  • Page 183 (Paragraph 1, Line 3): the methods end with the Async prefix, which should be the methods end with Async, which
  • Page 198: public async Task additem_should_add_right_entity() should be public async Task additem_should_add_the_entity()
  • Page 199: public async Task edititem_should_add_right_entity() should be public async Task edititem_should_edit_the_entity()

Related products

Get to Know the Author

Samuele Resca is a software engineer working at Just Eat and primarily focused on web technologies. He is a Microsoft Most Valuable Professional in Visual Studio and development technologies. Samuele writes software engineering blog posts on Samuele Resca โ€“ Blog and The DEV Community, and he contributes to open source projects. He is continuously learning and developing around the web ecosystem with a focus on the .NET Core ecosystem, cloud computing, serverless computing, and reactive programming. Samuele is from Italy, and he currently lives in London.

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Learn

  • Acquire a deep working knowledge of ASP.NET Core
  • Integrate third-party tools and frameworks to build maintainable and performant services
  • Implement patterns and good practices using dependency injection
  • Test an ASP.NET Core application using out-of-box tools of ASP.NET Core
  • Use docker to run your ASP.NET Core web service in an isolated and self-contained environment
  • Secure your information using HTTPS and token-based authentication
  • Integrate multiple web service using techniques such as resilient-clients and messaging

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781789537611

hands-on-restful-web-services-with-asp.net-core-3's People

Contributors

packt-itservice avatar packt-pradeeps avatar packtutkarshr avatar rohitpackt avatar samueleresca avatar shaileshj-packt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hands-on-restful-web-services-with-asp.net-core-3's Issues

Chaprter 13: Cannot post a new object neither in Catalog.Api nor in Cart.Api through swagger (using Net 5.0)

I launch my browser (http://localhost:...../swagger/index.html), and when I try to post a new object I get the following exception:
System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues. Path: $.DetailedMessage.TargetSite.DeclaringType.
---> System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues.
at System.Text.Json.Serialization.Converters.TypeConverter.Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex) at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteAsyncCore[TValue](Stream utf8Json, TValue value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeAlwaysRunResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Error in CatalogContext

I am getting below error

CS0411 The type arguments for method 'ModelBuilder.ApplyConfiguration(IEntityTypeConfiguration)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Catalog.Infrastructure C:\Sudhir\learningWebApi\catalog.api\Catalog.Infrastructure\CatalogContext.cs 27 Active

Using Visual Studio 2017, EF Core 2.2
SQL Server Express

As per Chapter 8, I have following code in CatalogContext

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new ItemEntitySchemaDefinition());
//modelBuilder.ApplyConfiguration(new GenreEntitySchemaConfiguration());
//modelBuilder.ApplyConfiguration(new ArtistEntitySchemaConfiguration());
base.OnModelCreating(modelBuilder);
}

Chapter05 curl -X POST doesn't work as expected.

Hello


I run Chapter05\SampleAPI\SampleAPI.csproj in Launch: Project Mode.
Visual Studio 2019


In the book Hands-On RESTful Web Services with ASP.NET Core 3.pdf
Chapter 5, Page 82
Line -
curl -X POST https://localhost:5001/api/order/ -H 'Content-Type: application/json' -d '{"itemsIds": ["1","4"]}' -i -k

Result should be

HTTP/1.1 201 Created
Date: Mon, 20 Aug 2018 11:19:49 GMT
Server: Kestrel
Content-Length: 0
Location:
https://localhost:5001/api/orders/372459c7-6e16-4276-b286-f341d7009c43

Result on my computer:

C:\>curl -X POST https://localhost:5001/api/order/ -H 'Content-Type: application/json' -d '{"itemsIds": ["1","4"]}' -i -k
HTTP/1.1 415 Unsupported Media Type
Date: Tue, 20 Oct 2020 17:37:33 GMT
Content-Type: application/problem+json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"|7e52c990-49b7b02ead9129a7."}curl: (6) Could not resolve host:
 application
curl: (3) [globbing] bad range in column 2

At the same time, Visual Studio does not catch any exceptions.
Although I put the Exception Settings - Common Language Runtime Exceptions - Check for All.

Although execution goes through the method

         public OrderController (IOrderRepository ordersRepository)
         {
             _orderRepository = ordersRepository;
         }

but the method

         [HttpPost]
         public IActionResult Post (OrderRequest request)
         {
             var order = Map (request);
            
             _orderRepository.Add (order);
            
             return CreatedAtAction (nameof (GetById), new {id = order.Id}, null);
         }

not performed

Here is lo result:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\DelphiStuff\DotNet Samples\RESTful Web Services\RESTful-Web-Serv-ASPNETCore3\Code\Chapter05\SampleAPI
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 POST https://localhost:5001/api/order/ application/x-www-form-urlencoded 11
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'SampleAPI.Controllers.OrderController.Post (SampleAPI)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
      Route matched with {action = "Post", controller = "Order"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Post(SampleAPI.Requests.OrderRequest) on controller SampleAPI.Controllers.OrderController (SampleAPI).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
      Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ProblemDetails'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
      Executed action SampleAPI.Controllers.OrderController.Post (SampleAPI) in 68735.3007ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'SampleAPI.Controllers.OrderController.Post (SampleAPI)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 68797.074ms 415 application/problem+json; charset=utf-8

Chapter 13 is missing content on on-line book version.

Thank you for this excellent book. I am Using the online book interface on the packtpub website and I have noticed that Chapter 13: "Implementing the RESTful HTTP Layer", only has the introductory paragraph in each section but is missing the detailed code walk-through and explanation. This is a pity.

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.