Create nuget package from a REST web API application

Asked

Viewed 64 times

1

I have a WEB API REST service in ASP.NET CORE 2.0 multiple projects(layers) in it. However, by larger forces, it cannot be used as a service.

It was then suggested to create a nuget package for this WEB API. I have never created a nuget package and have seen examples on the internet of simple projects being used as nuget package and not a REST WEB API. The doubt is as follows:

I can generate a nuget package from my REST WEB API application?

--

** Edit

--

Force majeure => The fearful stackeholders

Type of Application => Audit Log (for several other applications)

Situation

Applications will not be able to do anything without logging in first and stackeholders are afraid that, by some chance, this API will stop working for some reason, and all applications that used this service will stop working.

--

Application Architecture

  • Controller
  • Application
  • Domain
  • Repository
  • etc....

1º) I would need to change the Architecture?

2º) If it is possible to use this API as a nuget package, would I use it as a service? For example I have the GET route: http://localhost/api/logs. Would I use these controller routes? Or would I access the API resources otherwise?

  • Could you clarify which are the larger forces?

1 answer

1

Yes, nothing prevents you from implementing a Nuget package that when invoked prepares endpoints Webapi.

This scenario can be useful when you are developing a web application compatible with endpoints REST.

This is the case for the following library:

https://github.com/bucknellu/Nyan

Note that one of the modules (https://github.com/bucknellu/Nyan/tree/master/Modules/Web/REST) aims to provide functionalities such as endpoints Webapi.

Incidentally this module is also available as a Nuget package:

https://www.nuget.org/packages/Nyan.Modules.Web.REST/

So answering your questions:

1º) I would need to change the Architecture?

Not. It can be maintained in the same way. The only thing you need to guarantee is that the API controllers of the Nuget package are loaded and made available in the same way.

2º) If it is possible to use this API as a nuget package, would I use it as a service? For example I have the GET route: http://localhost/api/logs. Would I use these controller routes? Or would I access the API resources otherwise?

Yes. The only difference between your application’s controllers and those of the (s) Nuget package(s) is the Assembly where they are located.

When you embed a package into your application, what you are actually doing is performing the download of a set of assemblies that will be referenced by your project.

When running your web application will be made available under a URL where all the endpoints - both of its application as those present in referenced assemblies.

So you can continue to use local relative Urls to access endpoints (api/logs, for example.)

  • Thanks for the reply, so would I communicate with this nuget package the same way I would as a service? For example via GET: api/Locations, to redeem the locations? I will edit and exemplify them better in my question.

  • @Leofelipe I expanded the response to cover your use case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.