I have implemented a REST API middleware application in Flask. There is a Rest API host and a client. In the middle of those there is my application which gets request from client and sends it to Rest API host. Than gets response from REST API host and sends
it to the client. It works but I would like to implement it with VS Web API.
In Flask I am parsing json requests/responses and save to database. I am not sure if this is a good idea. I am planning to save the JSON request/response without parsing. What are your opinions? In any conflict situation, I will give JSON request/response
messages to the related parties. How would you design your database? What are advantages/disadvantages of saving JSON to Database?
Thanks in advance.
Best Regards.
Keep your friends close and your enemies even closer
I am not sure if this is a good idea. I am planning to save the JSON request/response without parsing.
I assume this is an ASP.NET Core application as that's the subject of your other threads. It is impossible to save a request or a response in Web API without parsing the HTTP message.
It seems you want a proxy which has nothing to do with ASP.NET
It is common to parse the json for validation, but if you’re code is just a proxy server, and it only logs the json, then a parse may not be needed. Also depending on the database you pick, it may validate the json.
If you plan to query the data at a later time then saving the data in a database is an advantage. Otherwise the data takes up space and is a disadvantage.
Actually I will not query data unless client and host have conflict. If client says on this date and time I sent this but in response you gave me that. In a sitation like this I want to save JSON request from client and response from Host just for precaution.
Should I Convert JSONObject into String and save as TEXT/ VARCHAR in DB?
String stringToBeInserted = jsonObject.toString();
//and insert this string into DB
Keep your friends close and your enemies even closer
You should use VARCHAR(MAX) or NVARCHAR(MAX) instead to store json string ,TEXT, NTEXT are deprecated as of SQL Server 2005 . With SQL Server 2016 and Azure SQL, there are a lot of additional native JSON capabilities such as FOR JSON command to convert
output from a query into JSON format :
The nvarchar(max) data type lets you store JSON documents that are up to 2 GB in size. If you're sure that your JSON documents aren't greater than 8 KB, however, we recommend that you use NVARCHAR(4000) instead of NVARCHAR(max) for performance reasons.
Member
526 Points
2722 Posts
Rest API middleware suggestions
Jan 16, 2019 05:58 AM|cenk1536|LINK
Hello,
I have implemented a REST API middleware application in Flask. There is a Rest API host and a client. In the middle of those there is my application which gets request from client and sends it to Rest API host. Than gets response from REST API host and sends it to the client. It works but I would like to implement it with VS Web API.
In Flask I am parsing json requests/responses and save to database. I am not sure if this is a good idea. I am planning to save the JSON request/response without parsing. What are your opinions? In any conflict situation, I will give JSON request/response messages to the related parties. How would you design your database? What are advantages/disadvantages of saving JSON to Database?
Thanks in advance.
Best Regards.
All-Star
120146 Points
27989 Posts
Moderator
MVP
Re: Rest API middleware suggestions
Jan 16, 2019 12:54 PM|ignatandrei|LINK
Do you retrieve the whole JSON for a document ?
Do you want to filter more JSON's for a criteria ?
Do you want to paginate those filters ?
Do you want to export ( into CSV, WORD, EXCEL, PDF) parts of the JSON ?
If yes to all or many, re-think your database in relational / reports way
Member
526 Points
2722 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 01:33 PM|cenk1536|LINK
Hi,
I actually store JSON request/response for logging in case of conflicts. I don't want to filter, paginate or export.
Best Regards.
All-Star
52101 Points
23231 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 03:00 PM|mgebhard|LINK
I assume this is an ASP.NET Core application as that's the subject of your other threads. It is impossible to save a request or a response in Web API without parsing the HTTP message.
It seems you want a proxy which has nothing to do with ASP.NET
All-Star
57864 Points
15488 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 03:05 PM|bruce (sqlwork.com)|LINK
Member
526 Points
2722 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 06:10 PM|cenk1536|LINK
Advantages/disadvantages of storing JSON request/response in database?
Here is a sample JSON response:
All-Star
52101 Points
23231 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 06:21 PM|mgebhard|LINK
Only you can answer this question.
If you plan to query the data at a later time then saving the data in a database is an advantage. Otherwise the data takes up space and is a disadvantage.
Member
526 Points
2722 Posts
Re: Rest API middleware suggestions
Jan 16, 2019 06:25 PM|cenk1536|LINK
Actually I will not query data unless client and host have conflict. If client says on this date and time I sent this but in response you gave me that. In a sitation like this I want to save JSON request from client and response from Host just for precaution.
Should I Convert JSONObject into String and save as TEXT/ VARCHAR in DB?
All-Star
18815 Points
3831 Posts
Re: Rest API middleware suggestions
Jan 18, 2019 02:43 AM|Nan Yu|LINK
Hi cenk1536,
You should use VARCHAR(MAX) or NVARCHAR(MAX) instead to store json string ,TEXT, NTEXT are deprecated as of SQL Server 2005 . With SQL Server 2016 and Azure SQL, there are a lot of additional native JSON capabilities such as FOR JSON command to convert output from a query into JSON format :
https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-2017
The nvarchar(max) data type lets you store JSON documents that are up to 2 GB in size. If you're sure that your JSON documents aren't greater than 8 KB, however, we recommend that you use NVARCHAR(4000) instead of NVARCHAR(max) for performance reasons.
Best Regards,
Nan Yu