Download - Symfony ile Gelişmiş API Mimarisi
Symfony ile Gelişmiş API Mimarisi
Behram ÇELEN
Software Developer
github.com/behramcelen
twitter.com/behramcelen
API
● Application Programming Interface
● REST
● Facebook/Twitter.. API
● Postman
● Swagger
● RESTful API
● JSON and XML
● Versioning
Symfony Bundles
● FOSRestBundle
● NelmioApiDocBundle
https://github.com/FriendsOfSymfony/FOSRestBundlehttps://github.com/nelmio/NelmioApiDocBundle
API Methods
● GET
● POST
● PUT
● PATCH
● DELETE
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
GET
● Değişikliğe neden olmamalı
● Cache Kullanılabilir
● Resource veya Resource Collection dönmeli
● Offset ve Limit olmalı (Collection için)
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3
POST
● Resource create
● Validation
● Hata veya resource location dönmeli
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5
PUT
● Create resource if not exists
● Validation
● Eğer resource varsa güncellemeli
● Yoksa resource u oluşturmalı
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6
PATCH
● Resource yoksa 404 dönmeli
● Validation
● Resource un belirli fieldları güncellenebilir
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6
DELETE● Resource yoksa 404
dönmeli
● Resource varsa silinmeli
● NULL content dönmeli
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7
FOSRestBundle● Kurulum
● JMSSerializerBundle
● Handlers
● Routing
http://symfony.com/doc/master/bundles/FOSRestBundle/1-setting_up_the_bundle.htmlhttp://jmsyst.com/libs/serializerhttps://github.com/ojs/ojs/tree/master/src/Ojs/ApiBundle/Handlerhttps://github.com/ojs/ojs/blob/master/src/Ojs/ApiBundle/Resources/config/routing_rest.yml
NelmioApiDocBundle
● Swagger Doc Support
● View Layer
● Annotation
● Commands
● HTML, Markdown, JSON do dump
● Sandbox Supporthttps://github.com/nelmio/NelmioApiDocBundle/blob/master/Resources/doc/index.rsthttps://github.com/ojs/ojs/blob/master/src/Ojs/ApiBundle/Controller/Journal/JournalArticleAuthorRestController.php#L150
Routing
https://github.com/ojs/ojs/blob/master/app%2Fconfig%2Frouting_rest.ymlhttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FResources%2Fconfig%2Frouting_rest.yml
Security● ACL
● ApiKey Auth
Related Links
https://github.com/ojs/ojs/blob/master/app/config/security.yml#L20https://github.com/ojs/ojs/blob/a8f11d6b7fd351a837a21ece92f487a3ca978d71/app/config/services.yml#L14https://github.com/ojs/ojs/blob/master/src/Ojs/ApiBundle/Security/ApiKeyUserProvider.php#L20https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FSecurity%2FApiKeyAuthenticator.php#L16https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FController%2FAdmin%2FArticleTypeRestController.php#L44
Handlers
https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FResources%2Fconfig%2Fservices.ymlhttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FHandler%2FArticleTypeHandler.phphttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FController%2FAdmin%2FArticleTypeRestController.php#L129
Exception
https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FException%2FInvalidFormException.phphttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FController%2FAdmin%2FArticleTypeRestController.php#L45https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FController%2FAdmin%2FArticleTypeRestController.php#L277https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FSecurity%2FApiKeyAuthenticator.php#L31
Validation
https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FHandler%2FArticleTypeHandler.php#L119https://github.com/ojs/ojs/blob/master/src%2FOjs%2FAdminBundle%2FForm%2FType%2FArticleTypesType.phphttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FJournalBundle%2FResources%2Fconfig%2Fvalidation%2FJournal.yml
Serializer
http://jmsyst.com/libs/serializerhttp://jmsyst.com/libs/serializer/master/reference/annotationshttps://github.com/ojs/ojs/blob/master/src%2FOjs%2FJournalBundle%2FEntity%2FArticle.php#L26
Tests
https://github.com/ojs/ojs/tree/master/src/Ojs/ApiBundle/Tests/Controller
File Upload
https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FTests%2FController%2FJournalIssueRestControllerTest.php#L25https://github.com/ojs/ojs/blob/master/src%2FOjs%2FApiBundle%2FHandler%2FJournalIssueHandler.php#L162
Teşekkü[email protected]