I am looking for a way to make REST API endpoints based on models, I know that this is possible within Django. But I haven't found a similar way to do this in asp.net core, is there any framework for this platform that provides this functionality?
How it works in django when you use the djangorestframework:
Define a model, auto migrate everything:
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
That model is used to create an endpoint. A Serializer decides which fields are shown:
class PersonSerializer(serializers.ModelSerializer):
class Meta:
model = Person
exclude = ()
A viewset for the ORM Query:
class PersonViewSet(viewsets.ModelViewSet):
queryset = Person.objects.all()
serializer_class = PersonSerializer
And some routermapping:
router = DefaultRouter()
router.register(r'persons', PersonViewSet)
urlpatterns = [
path('', include(router.urls)),
]
And now I have an API that can
- GET /person - list all persons
- GET /person/1 - give details of a specific person
- POST /person - create a person
- PUT /person/1 - update a person
- DELETE /person/1 - delete a person
Is there anything similar in asp.net core?