1

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

  1. GET /person - list all persons
  2. GET /person/1 - give details of a specific person
  3. POST /person - create a person
  4. PUT /person/1 - update a person
  5. DELETE /person/1 - delete a person

Is there anything similar in asp.net core?

Oxidda
  • 33
  • 6

1 Answers1

1

You could have a look at generic controllers, see e.g.:

user7217806
  • 2,014
  • 2
  • 10
  • 12
  • Aye, but there is no framework or such that has this altogether as in out of the box? I was building it myself but I was thinking "Surely someone did this" but doesnt seem to be the case. – Oxidda May 17 '20 at 16:12
  • Unfortunately not that I am aware of. It probably is too easy to generate controllers :). – user7217806 May 17 '20 at 21:35
  • @user7217806 Why don't we just write everything in assembler, I mean everything is too easy if you think about it, right? – Sem May 20 '20 at 18:25
  • @Sem Please note the smiley, I am of course not being serious about this statement. – user7217806 May 20 '20 at 19:24
  • 1
    Accepted this as the answer, I bascially made my own Framework to facilitate this, with the help of above information, see: https://github.com/oxidda/leatherback – Oxidda Jun 23 '20 at 12:32