{"id":15148466,"url":"https://github.com/furkancosgun/abap-zen-api","last_synced_at":"2026-01-20T02:48:11.150Z","repository":{"id":254620565,"uuid":"847033079","full_name":"furkancosgun/ABAP-ZEN-API","owner":"furkancosgun","description":"Zen API is a flexible and straightforward HTTP framework designed specifically for ABAP environments. It enables efficient handling of HTTP requests and responses using routes, middleware, and API definition classes.","archived":false,"fork":false,"pushed_at":"2024-08-24T18:04:07.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T02:47:27.438Z","etag":null,"topics":["abap","abapgit","api","api-rest","framework","request","response","rest-api","sap"],"latest_commit_sha":null,"homepage":"","language":"ABAP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/furkancosgun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-24T16:50:49.000Z","updated_at":"2024-08-28T08:42:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"c1e0e79b-5d24-42e5-9532-4eb31817afef","html_url":"https://github.com/furkancosgun/ABAP-ZEN-API","commit_stats":null,"previous_names":["furkancosgun/abap_zen_api","furkancosgun/abap-zen-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkancosgun%2FABAP-ZEN-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkancosgun%2FABAP-ZEN-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkancosgun%2FABAP-ZEN-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkancosgun%2FABAP-ZEN-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/furkancosgun","download_url":"https://codeload.github.com/furkancosgun/ABAP-ZEN-API/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247584061,"owners_count":20962071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abap","abapgit","api","api-rest","framework","request","response","rest-api","sap"],"created_at":"2024-09-26T13:03:57.097Z","updated_at":"2026-01-20T02:48:11.122Z","avatar_url":"https://github.com/furkancosgun.png","language":"ABAP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ABAP Zen API\n\nZen API is a flexible and straightforward HTTP framework designed specifically for ABAP environments. It enables efficient handling of HTTP requests and responses using routes, middleware, and API definition classes.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE). See the LICENSE file for details.\n\n## Contents\n\n- [API Definition Example](#api-definition-example)\n- [Route Example](#route-example)\n- [Middleware Example](#middleware-example)\n- [Request Interface](#request-interface)\n- [Response Interface](#response-interface)\n\n### API Definition Example\n\nThis section explains how to define an API using the Zen API Framework. By extending the `zcl_zen_api_manager` class, you can configure routes for different HTTP methods and register middleware to handle requests. Additionally, you will set the base path for the API.\n\n**Steps to Define an API:**\n\n1. **Create a New API Class**: Inherit from the `zcl_zen_api_manager` class and override its methods to set up routes and middleware.\n\n2. **Define Routes**: In the `constructor` method, create instances of route handler classes and associate them with HTTP methods (GET, POST, PUT, etc.). This allows your API to manage requests across various endpoints.\n\n3. **Register Middleware**: Middleware processes requests before they reach the route handlers. Register your middleware using the `me-\u003euse( middleware = ... )` statement.\n\n4. **Specify the Base Path**: Override the `get_root` method to set the base path for the API. Ensure this path matches the configuration in the SICF transaction code.\n\nHere’s an example implementation of an API class:\n\n```abap\nCLASS zcl_zen_api_demo_api DEFINITION\n  PUBLIC\n  INHERITING FROM zcl_zen_api_manager\n  FINAL\n  CREATE PUBLIC .\n\n  PUBLIC SECTION.\n    METHODS:\n      constructor,            \" Initializes API routes and middleware\n      get_root REDEFINITION.  \" Defines the base path for the API\nENDCLASS.\n\nCLASS zcl_zen_api_demo_api IMPLEMENTATION.\n\n  METHOD constructor.\n    \" Initialize the base API settings\n    super-\u003econstructor( ).\n\n    \" Create instances of route and middleware classes\n    DATA(lo_route) = NEW zcl_zen_api_demo_route( ).\n    DATA(lo_middleware) = NEW zcl_zen_api_demo_middleware( ).\n\n    \" Define API routes and associate them with route handlers\n    me-\u003eget( path = '' route = lo_route ).\n    me-\u003epost( path = '' route = lo_route ).\n    me-\u003eput( path = '' route = lo_route ).\n    me-\u003epatch( path = '' route = lo_route ).\n    me-\u003edelete( path = '' route = lo_route ).\n    me-\u003ehead( path = '' route = lo_route ).\n\n    \" Register the middleware for request processing\n    me-\u003euse( middleware = lo_middleware ).\n  ENDMETHOD.\n\n  METHOD get_root.\n    \" Set the base path for this API\n    \" This path should match the one configured in SICF\n    root = '/zen_api/demo'.\n  ENDMETHOD.\n\nENDCLASS.\n```\n\n### Route Example\n\nIn the Zen API Framework, a route class handles incoming HTTP requests and generates responses based on the request data. To implement a route class, you need to use the `zif_zen_api_route` interface, which includes the `on_request` method for processing requests.\n\n**Steps to Create a Route Class:**\n\n1. **Define the Route Class**: Create a new class that implements the `zif_zen_api_route` interface. This interface requires you to implement the `on_request` method.\n\n2. **Implement the `on_request` Method**: This method is where you handle the HTTP request, perform necessary data retrieval, and prepare the response. Use `io_request` to access request details and `io_response` to send the response.\n\nHere’s an example implementation of a route class:\n\n```abap\nCLASS zcl_zen_api_demo_route DEFINITION\n  PUBLIC\n  FINAL\n  CREATE PUBLIC .\n\n  PUBLIC SECTION.\n    INTERFACES: zif_zen_api_route. \" Implements the route interface for handling requests\nENDCLASS.\n\nCLASS zcl_zen_api_demo_route IMPLEMENTATION.\n\n  METHOD zif_zen_api_route~on_request.\n    \" Fetch data from a database table\n    SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).\n\n    \" Send a response with status code OK and JSON content\n    io_response-\u003esend(\n        status_code = zcl_zen_api_status_codes=\u003ec_ok\n        content_type = zcl_zen_api_content_types=\u003ec_application_json\n        data = /ui2/cl_json=\u003eserialize( data = lt_scarr pretty_name = /ui2/cl_json=\u003epretty_mode-camel_case )\n    ).\n  ENDMETHOD.\n\nENDCLASS.\n```\n\n### Middleware Example\n\nMiddleware processes HTTP requests and responses before they reach the route handlers or after the responses are generated. Implement middleware by extending the `zif_zen_api_middleware` interface, which provides the `process` method for handling requests.\n\n**Steps to Create a Middleware Class:**\n\n1. **Define the Middleware Class**: Create a new class that implements the `zif_zen_api_middleware` interface. This interface requires the implementation of the `process` method.\n\n2. **Implement the `process` Method**: This method allows you to perform operations such as logging or modifying requests. Use the `has_next` parameter to decide whether to continue processing with the next middleware or route handler.\n\nHere’s an example implementation of a middleware class:\n\n```abap\nCLASS zcl_zen_api_demo_middleware DEFINITION\n  PUBLIC\n  FINAL\n  CREATE PUBLIC .\n\n  PUBLIC SECTION.\n    INTERFACES: zif_zen_api_middleware. \" Implements the middleware interface for processing requests\nENDCLASS.\n\nCLASS zcl_zen_api_demo_middleware IMPLEMENTATION.\n\n  METHOD zif_zen_api_middleware~process.\n    \" Perform actions such as logging the request or modifying it\n    \" Example: Log the request details or perform other tasks\n\n    \" Decide whether to continue processing the request\n    has_next = abap_true.\n  ENDMETHOD.\n\nENDCLASS.\n```\n\n### Request Interface\n\nThe `zif_zen_api_request` interface defines the available properties and methods for handling HTTP requests.\n\n**Properties:**\n\n- `root`: The base path of the API. (e.g., `/api/v1`)\n- `path`: The endpoint path of the current request. (e.g., `/users`)\n- `full_path`: The full path of the request, combining `root` and `path`. (e.g., `/api/v1/users`)\n- `method`: The HTTP method of the request (GET, POST, etc.).\n- `query_parameters`: The query parameters of the request.\n- `content_type`: The content type of the request.\n- `headers`: The headers of the request.\n- `form_data`: The form data submitted with the request.\n- `body`: The body of the request.\n- `raw`: The raw request data.\n\n### Response Interface\n\nThe `zif_zen_api_response` interface defines the available methods for sending HTTP responses.\n\n**Methods:**\n\n- `send`: Sends the response with a specified status code, content type, and optional data. The `data` parameter can be of type `string` or `xstring`.\n\n  ```abap\n  METHODS:\n    send\n      IMPORTING\n        status_code  TYPE i DEFAULT zcl_zen_api_status_codes=\u003ec_ok\n        content_type TYPE string DEFAULT zcl_zen_api_content_types=\u003ec_application_json\n        data         TYPE any OPTIONAL. \" Should be of type string or xstring\n  ```\n\n- `redirect`: Redirects the request to a different URL with a specified status code.\n\n  ```abap\n  METHODS:\n    redirect\n      IMPORTING\n        status_code TYPE i DEFAULT zcl_zen_api_status_codes=\u003ec_found\n        url         TYPE string.\n  ```\n\n- `set_header`: Sets a response header with a specified name and value.\n\n  ```abap\n  METHODS:\n    set_header\n      IMPORTING\n        name  TYPE string\n        value TYPE string.\n  ```\n\nThese interfaces provide the essential functionalities for handling and responding to HTTP requests in the Zen API Framework.\n\nFeel free to adjust any details according to your specific needs or preferences.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffurkancosgun%2Fabap-zen-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffurkancosgun%2Fabap-zen-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffurkancosgun%2Fabap-zen-api/lists"}