-
Notifications
You must be signed in to change notification settings - Fork 0
Creating Actions
The only caveat for some people right now is that the only way to create actions (api calls) is through the administration interface. We have a ticket opened in case anyone feels like doing a CLI program to use alternatively instead of the administration interface (https://github.com/frapi/frapi/issues#issue/4)
Now that you successfully setup Frapi (Both the admin and the frontend side) you must create your first action. As the Running on nginx and the Running on Apache pages refer to the administration interface url as http://admin.frapi, I’ll use that URL in this example.
Firstly you must go to the admin interface and login. Once this is done click on “Actions” 
and you will be directed to this screen

and as the arrow suggests, click on “Add new Action”.
Add new action will prompt you with a form that has various information about your action as shown in the following image 
- Name: This is the name of the action you are creating (The file with code that will be generated with that name).
- Enabled: Is the action available? Should people be able to use this action?
- Public: If you want an action to be only accessible by parnters (See partners section of Frapi) you may leave this box unchecked. However if you want to make an action that is public to everybody, you want to check that box.
- Custom Route: Right now this is a very simple routing system as explained briefly in Simple Routing. For the purpose of this example just put /testing/2
- Description: The description is used for documentation purposes. Frapi has an API documentation generation system and when generating API documentation, it uses the description you put for an action to describe it. This generated documentation can be used by third party developers that are using your API.
As you logged in you might have noticed something at the bottom that says: “Add parameters”. This was being kept secret as it requires it’s own explanation with a bit more details than the other fields up there. As you can see 
the “Add parameter” is not very impressive however if you click on it you will get prompted with a new field

After editing your action and adding parameters, click save. If all went well you should see a message that says: “Action {NAME} Added”
Now that the action is created, you need to synchronize the codebase (This means that new actions will get some generated code). If you look at the top right of your administration interface you should see a “Sync Now” button 
When you click on that button Frapi grabs all the actions you created and generates the skeleton for the actions in the code base.
.
When it’s done synchronizing, you will get a message that says “Development environment has been sychronized” and if you go to your Frapi “custom” directory (Which is located in FRAPI_PATH/src/frapi/custom) you will see a folder called “Action” which will now contain the action you just created/synchronized.
The generated action code looks like this: Testing2.php
You are now ready to code. Just add your own code for GET requests in executeGet(), same for POST executePost(), PUT executePut(), DELETE executeDelete() and HEAD executeHead().