Ils exposeront et consommeront vos données :
JavaScript Object Notation
REpresentational State Transfer
Hypermedia as the Engine of Application State
JSON for Linked Data
{
"@context": "http://schema.org",
"@type": "Event",
"location": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "Denver",
"addressRegion": "CO",
"postalCode": "80209",
"streetAddress": "7 S. Broadway"
},
"name": "The Hi-Dive"
},
"name": "Typhoon with Radiation City",
"offers": {
"@type": "Offer",
"price": "13.00",
"priceCurrency": "USD",
"url": "http://www.ticketfly.com/purchase/309433"
},
"startDate": "Sat Sep 14"
}
Une solution facile à prendre en main, évolutive et intégrée pour réaliser des API REST.
github.com/dunglas/api-platform
bookstore-api.dunglas.fr (si t'as curl
sur ton iPhone)
composer create-project dunglas/api-platform --stability=dev my-api
namespaces:
entity: AppBundle\Entity
types:
Thing:
properties:
name: ~
url: ~
Person:
properties:
birthDate: ~
gender: ~
bin/schema generate-types src/ app/config/schema.yml
ResolveTargetEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A person (alive, dead, undead, or fictional).
*
* @see http://schema.org/Person Documentation on Schema.org
*
* @ORM\Entity
*/
class Person extends Thing
{
/**
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string An additional name for a Person, can be used for a middle name.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $additionalName;
/**
* @var PostalAddress Physical address of the item.
* @ORM\ManyToOne(targetEntity="PostalAddress")
*/
private $address;
/**
* @var \DateTime Date of birth.
* @Assert\Date
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
/**
* @var string Email address.
* @Assert\Email
* @ORM\Column(nullable=true)
*/
private $email;
/**
* @var string Family name. In the U.S., the last name of an Person. This can be used along with givenName instead of the name property.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $familyName;
/**
* @var string Gender of the person.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $gender;
/**
* @var string Given name. In the U.S., the first name of a Person. This can be used along with familyName instead of the name property.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $givenName;
/**
* @var string The job title of the person (for example, Financial Manager).
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $jobTitle;
/**
* @var string The telephone number.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $telephone;
/**
* Sets id.
*
* @param integer $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Gets id.
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Sets additionalName.
*
* @param string $additionalName
* @return $this
*/
public function setAdditionalName($additionalName)
{
$this->additionalName = $additionalName;
return $this;
}
/**
* Gets additionalName.
*
* @return string
*/
public function getAdditionalName()
{
return $this->additionalName;
}
/**
* Sets address.
*
* @param PostalAddress $address
* @return $this
*/
public function setAddress(PostalAddress $address)
{
$this->address = $address;
return $this;
}
/**
* Gets address.
*
* @return PostalAddress
*/
public function getAddress()
{
return $this->address;
}
/**
* Sets birthDate.
*
* @param \DateTime $birthDate
* @return $this
*/
public function setBirthDate(\DateTime $birthDate)
{
$this->birthDate = $birthDate;
return $this;
}
/**
* Gets birthDate.
*
* @return \DateTime
*/
public function getBirthDate()
{
return $this->birthDate;
}
/**
* Sets email.
*
* @param string $email
* @return $this
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Gets email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Sets familyName.
*
* @param string $familyName
* @return $this
*/
public function setFamilyName($familyName)
{
$this->familyName = $familyName;
return $this;
}
/**
* Gets familyName.
*
* @return string
*/
public function getFamilyName()
{
return $this->familyName;
}
/**
* Sets gender.
*
* @param string $gender
* @return $this
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* Gets gender.
*
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* Sets givenName.
*
* @param string $givenName
* @return $this
*/
public function setGivenName($givenName)
{
$this->givenName = $givenName;
return $this;
}
/**
* Gets givenName.
*
* @return string
*/
public function getGivenName()
{
return $this->givenName;
}
/**
* Sets jobTitle.
*
* @param string $jobTitle
* @return $this
*/
public function setJobTitle($jobTitle)
{
$this->jobTitle = $jobTitle;
return $this;
}
/**
* Gets jobTitle.
*
* @return string
*/
public function getJobTitle()
{
return $this->jobTitle;
}
/**
* Sets telephone.
*
* @param string $telephone
* @return $this
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Gets telephone.
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
}
# app/config/services.yml
services:
person_resource:
parent: "dunglas_json_ld_api.resource"
arguments: [ "AppBundle\Entity\Person" ]
tags: [ { name: "json-ld.resource" } ]
GET
, POST
, PUT
, DELETE
)dev-master
) détecte automatiquement les resources exposées
par le bundle.
POST
)Resource
et contrôleurs personnalisés
<script type="application/ld+json">
{ "@context" : "http://schema.org",
"@type" : "Organization",
"url" : "http://www.your-company-site.com",
"contactPoint" : [
{ "@type" : "ContactPoint",
"telephone" : "+1-401-555-1212",
"contactType" : "customer service"
} ] }
</script>