0

I am working on a web service project using c# that needs to detect a RESTful api call from the javascript code extracted from a given html string.

I need to parse the js code and analyze it to get the RESTful api to build a call for it later using c#.

I have read about converting js code into c# classes and found tools like Jurrasic but it does not do what I need.

  • What have you tried so far? Can you show us an example of the input/output? – Haytam Apr 02 '21 at 15:54
  • Does this answer your question? [Deserialize JSON into C# dynamic object?](https://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object) – vaheeds Apr 03 '21 at 05:29
  • input: javascript code output: RESTful api that was called using the given js functions – Eman Abdelmohsen Apr 03 '21 at 15:30

1 Answers1

0

I do not think that you have to convert javascript code into c#

You may use the OpenAPI to create a REST api methods and objects definitions.

Then there are tools to generate C# client|server stubs and Dto classes. Like the Swagger codegen or json2csharp

This is the very good way to have REST API definition. Then you can share this definition between different teams|projects.

Or you may try the following dynamic deserialization approach

dynamic data = JsonConvert.DeserializeObject<dynamic>(json);

it allows to get dynamic object from the json string.

I suppose that you can even create code that will parse path are being requested by the Javascript code but there are the holy ASP.NET Web APIs implemented already.

oleksa
  • 3,688
  • 1
  • 29
  • 54
  • Could you please provide me with a tutorial on how to generate an openAPI specification for an api from javascript code using c#? – Eman Abdelmohsen Apr 03 '21 at 15:29
  • @EmanAbdelmohsen I do not know the way how to build openAPI from jsvascript code. It works in the opposite way usually – oleksa Apr 05 '21 at 07:20