How to build your client from Swagger specifications?

Cüneyt
5bayt
Published in
2 min readMay 13, 2020

In web applications there are many ways to generate a client which works like an api handler for javascript libraries, frameworks or just for a programming language while working with Swagger.

What is Swagger?

Swagger accually allows you to describe your rest based apis with a specific template design.

More you can read:

We will talk about the stage after these apis are written and the scheme is received from Swagger. If you visit the online swagger editor, you can see an example of the scheme here:

Let’s talk about the default example of swagger has. There is a tab named “Generate Client” which has many options at the top of the page. You can choose one of them which is suitable for you. If you ask me i need an angular client. When you click that it gives the client as an exported zip file.

It creates all services as an injectable services with headers, base urls and models as an interface for angular. So you don’t need to write anymore, you just need to inject them into your components. The important point here is you do not have to validate your response by createting model classes or interfaces so very useful.

MoreFolder structure of client

More important when you deploy your services to a server or still in your local you may also write your own script with node js for createting your client automatically. You can add command to your package.json to make your services ready.

I also recommend you to review another package named “nswag” alternatively to use generating client. Default it expects that you have alredy installed .NET 4.6.1+ or .NET Core 1.0/1.1/2.0/2.1/2.2 to be installed on your computer. But if you don’t it also allows you to change the runtime environment to WinX86 etc.

Thanks for your reading.

--

--