Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I cannot for the life of me figure out how to create a custom "hello world" type service with 8.x. I've tried copying and modifying some of the files in services/src/Plugin/ServiceDefinition into mymodule/src/Plugin/ServiceDefinition, but it doesn't seem to do anything. I would have expected to see my custom service show up on admin/structure/service_endpoint/[my_endpoint]/resources but it's not there. How do I achieve this?
Comments
Comment #2
Gravypower CreditAttribution: Gravypower commentedHey MKorostoff,
I had the same problem, after looking into how the resources page is built I had to make sure the namespace was correct on my Service Definition. Not sure if this is the issue you are having but thought it was worth mentioning.
Aaron
Comment #3
MKorostoff CreditAttribution: MKorostoff commented@Gravypower care to share your code?
Comment #4
Gravypower CreditAttribution: Gravypower commentedI put together an example for you
I then use Postman (a chrome extension) to test the service, the only thing you need to do is make sure you send the header "Accept:application/json" with the request or the service module will not respond. You can also use the Postman with xdebug with the Postman Interceptor extension this will send any cookies you have set in the browser on your target domain with the request.