composer create-project api-platform/api-platform blog-api
# app/config/schema.yml annotationGenerators: - ApiPlatform\SchemaGenerator\AnnotationGenerator\PhpDocAnnotationGenerator - ApiPlatform\SchemaGenerator\AnnotationGenerator\DoctrineOrmAnnotationGenerator - ApiPlatform\SchemaGenerator\AnnotationGenerator\ConstraintAnnotationGenerator - ApiPlatform\SchemaGenerator\AnnotationGenerator\DunglasApiAnnotationGenerator namespaces: entity: AppBundle\Entity types: SocialMediaPosting: ~ BlogPosting: ~ Article: properties: articleBody: ~ articleSection: ~ CreativeWork: properties: author: range: Person cardinality: (*..0) headline: ~ isFamilyFriendly: ~ datePublished: ~ Thing: properties: name: ~ Person: properties: {}
bin/schema generate-types src/ app/config/schema.yml
app/console doctrine:database:create
app/console doctrine:schema:create
# app/config/services.yml services: resource.blog_posting: parent: "api.resource" arguments: [ "AppBundle\\Entity\\BlogPosting" ] tags: [ { name: "api.resource" } ] resource.person: parent: "api.resource" arguments: [ "AppBundle\\Entity\\Person" ] tags: [ { name: "api.resource" } ]
app/console server:start
{ "name": "API Platform is great", "headline": "You'll love that framework!", "articleBody": "The body of my article.", "articleSection": "technology", "author": "/people/1", "isFamilyFriendly": "maybe", "datePublished": "2015-05-11" }
{ "@context": "/contexts/ConstraintViolationList", "@type": "ConstraintViolationList", "hydra:title": "An error occurred", "hydra:description": "isFamilyFriendly: This value should be of type boolean.\n", "violations": [ { "propertyPath": "isFamilyFriendly", "message": "This value should be of type boolean." } ] }
{ "name": "API Platform is great", "headline": "You'll love that framework!", "articleBody": "The body of my article.", "articleSection": "technology", "author": "/people/1", "isFamilyFriendly": true, "datePublished": "2015-05-11" }
Source: https://habr.com/ru/post/269377/
All Articles