Forum Discussion

1 Reply

  • MattV's avatar
    MattV
    Khoros Staff
    3 years ago

    Benefits of an endpoint:

    • Can make server-to-server calls, meaning you can hide API keys or 3rd party domains from the browser
    • You can do multiple operations in one request, and just return one result
    • You can return a result in your preferred output and format. This allows you to create a bespoke custom response
    • The endpoint can be reused by other code
    • The endpoint is a publicly accessible URL

    Drawbacks of an endpoint:

    • You are solely responsible for the entire output
    • You are responsible for all security measures in an endpoint
    • Endpoints can be hard to debug (no error output, have to look in toolbox and/or use logging)
    • The endpoint URL is a publicly accessible URL

    Note I included "publicly accessible" in both the pros/cons. This was intentional. It can be valuable to be able to use this endpoint from outside the community, but that also means you have to take that into consideration when building your endpoint and you may want to include checks for if the user is registered, and check if they have the expected roles.

    So, in the end it depends what you're trying to accomplish. For simple data fetches of public APIs, a straight JS ajax call is usually fine. But if you intend to add other logic or want custom output or intend to make community API calls, usually an Endpoint is the better option.