big OOF
❔ QuestionController
Hello, i have a question regarding API structure.
I have two classses, Item and Store. I created CRUD endpoints for both. Lets say i want to be able to return a store including all the items related to that store, and also be able to to POST a store with items. Would you create a seperate controller for these endpoints, for example StoreIemController containing PostStoreWithItems/GetAllStoresWithItems or use existing Store/ItemController?
Thanks in advance 🙂
9 replies
❔ Dev/prod databse
Hello,
Me and a friend wants to create a webb-app project with a react frontend and C# backend.
The idea was to use AWS RDS with mySQL for the final product.
To my question - what are the pros and cons/best practise of:
Set up and use a RDS(public so we both can acess it from our local) database from the start.
VS
We both use local mySQL for development and configure a "private" RDS at a later stage when the app is deployed on AWS?
Whats the most common way to approach this?
Thanks in advance! 🙂
6 replies
❔ Dezerialise JSON response
Example:
person
{
18370101 (changing social security number)
{
name: name, age: age description: "<p> This is a person with name and age </p>" } }
I want to dezerialise the json response into <Person> but the social security number dosent belong to a json property. From what i understand you can use something called Jtoken to solve this but it dosent feel quite right. Are there any alternatives? Also the field description contains html-elements, when im trying to dezerialise it throws an error, one again - any ideas? 🙂 Thanks in advance!
name: name, age: age description: "<p> This is a person with name and age </p>" } }
I want to dezerialise the json response into <Person> but the social security number dosent belong to a json property. From what i understand you can use something called Jtoken to solve this but it dosent feel quite right. Are there any alternatives? Also the field description contains html-elements, when im trying to dezerialise it throws an error, one again - any ideas? 🙂 Thanks in advance!
10 replies
❔ Retrieve API data in C#
What structure would you use if you want to create an API that retrieves data from another API and returns it to the user.
Im thinking:
1. API controller takes the GET request from user and calls the service class
2. Service class that makes the API call
At the moment im instantiating a httpClient in the service class but ideally i would want the functions in the service class to be static, but then i cant instantiate httpclient.
Is this the right "way/structure" to do it and/or do any tips regarding the static service class ? 🙂
Thanks!
20 replies
✅ API result
Hello,
I have two tables, group and person. These are created in Sqlite using EntityFramework and therefore the i have two classes like this:
From what i understand the line: "public ICollection<Group> Group{ get; set; }" creates a relation between the two tables(the id) when created by EF.
So to my question - when i try to retrieve Person via API(postman) i only get Id and Name. The goal is to get The person object but with Group nested in the JSON response.
Is there a step im missing? 🙂
Thanks in advance!
Thanks in advance!
86 replies
❔ Architecture
Hello,
If you have a API-controller class with a GET method inside. Lets say the GET should return a math calculation that is done in the function ExampleFunction(). The GET inside the api-controller needs to call the ExampleFunction.
So to my question, where should you place ExmapleFunction()? From what i understand:
- Not in the API controller
- Maybe inside a service class?
- Create a "general methods class"?
Thanks in advance 🙂
6 replies
❔ Understanding inheritance
Hello, im trying to understand a webshop example from microsoft. Im trying see what GetCardTypesAsync() does. (Attatched is the code from OrdersController)
When peeking the definition i only get to the interface "IOrderQueries" used by the OrdersController. I find the original function in another cs file "OrderQueries" (by searching for the function name) which inherits the interface but i really cant understand the connection between Orderqueries, the interface IOrderQueries and OrdersController. How does GetCardTypesAsync() in OrdersController know to use the function declared in OrderQueries just by using a interface? Anyone see what i dont? Let me know if you need additional info 🙂 Thanks in advance!
When peeking the definition i only get to the interface "IOrderQueries" used by the OrdersController. I find the original function in another cs file "OrderQueries" (by searching for the function name) which inherits the interface but i really cant understand the connection between Orderqueries, the interface IOrderQueries and OrdersController. How does GetCardTypesAsync() in OrdersController know to use the function declared in OrderQueries just by using a interface? Anyone see what i dont? Let me know if you need additional info 🙂 Thanks in advance!
20 replies
Create a app
Hi,
Me and a friend wanted to try and build a app for fun.
The first problem we faced was regarding choice of tech.
We are both beginners, im more into backend with C# and hes a frontend developer.
This is that we have come up with:
Hosting service
Azure/AWS
Database
MongoDB?
MySQL?
DBAAS on Azure or locally or have it on a separate server?
Frontend
React native
Backend
C# or node
Is this a good start or is there something vital that we have missed/forgotten?
Happy for any input 🙂
Thanks in advance!
20 replies
Declare method using T and where [Answered]
This is some code from a reddit post i saw and there are some thing i dont understand.
This is the method:
This is the interface that the method uses:
From what i understand, T is used to be able to make the method more "flixble", not restricting it to a specific return type.
But when adding "where T : IStudent" - it restricts it to only return a object that inherits the IStudent interface?
Could you not just replace T with IStudent and skip the where?
Plase let me know if i got in wrong 🙂
Thanks in advance!
38 replies
Call public method
Hello, Im trying to create a "config" which retrieves values from the appsettings.json file.
Ive created an example below:
How would you retrieve "UserName" from a different class?
Something like?
Or what would you say is best practice?
Thanks in advance! 🙂
3 replies
Api question
Hi,
I want to create a API that return data from another API, my question is regarding how to structure the code. You have the API controller with endpoints that gets called and returns a value. Where should i place the function that makes the call towards the second api?
1. It dosent sound too good to have it inside the api controller?
2. Should i create another class that hold all functions needed?
3. Add another class library project?
4. Include methods in the model classes?
Thanks in advance 🙂
15 replies
Display base64 img on Razor page
Hello,
Im trying to display a base 64 image on a razor page.
Pagemodel:
Page:
The image is not showing and im woundering if this is the correct way of thinking or should i change it from void to something that reloads the page?
Thanks in advance! 🙂
Thanks in advance! 🙂
9 replies
Exception vs Logic
Hello, im going to read a file with File.Readlines().
I read that its better to use logic(like a if-statement) rather then try/catch.
Which of these two would you say is better practice?
Option 1.
try{
fileLines = File.ReadAllLines(fileName);
}catch { throw; }
Option 2.
if (File.Exists(fileName))
{
try
{
fileLines = File.ReadLines(fileName);
}
catch { throw; }
}else { throw new FileNotFoundException(); }
Im thinking option 1 will throw filenotfoundexception either way, and therefore its no reason to check it like in option 2?
Thanks in advance!
76 replies