Skip to content

Let's Get Started

Julio Carneiro edited this page Dec 15, 2017 · 11 revisions

So, let's get started on a new project using the REST Api component and this JS44D library.

You have a couple options to start a new Angular project that talks to 4D using these components, but the first thing is to get your 4D Database Application ready.

Get 4D Application Ready

First download the RESTApi component. Easier to get the .zip version, unless you want to clone the repository. Then copy the REST_API.4dbase from directory REST_API_Build/Components/ into your application's source Components folder, and restart your 4D Application.

Make sure you enable 4D Web Server on your application and then proceed to create/copy the host methods that are required by this component. You can use the method source files in the Samples folder. Create each method and import them from that folder, not forgetting to set them as shared with components.

As an alternative, you can start another copy of 4D and open the SampleMethods.4dbase database found in the same Samples directory. Then you can simply copy the methods between the two 4D instances.

Except for the On Web Authentication method. You'll have to add a call to RESTOWA to your own OWA, or create one and copy its contents from the corresponding sample.

You may have to edit/adjust some of those host methods to adhere to your own application characteristics:

  • users_ValidateUser - the sample tries to authenticate a user via 4D's password system; if you have your own user/password management system on your application you'll probably need to make adjustments to this sample
  • users_GetUserGroups - the sample build's a user's group list using 4D's password system; if you have your own user/password management system on your application you'll probably need to make adjustments to this sample
  • users_GetUserOptions - you may need to modify this sample to add your own application requirements for user privileges/properties

Check if your 4D Application is ready to go

There is a simple way to test if your 4D Application is ready to go the RESTApi. You can download the FourDAdmin web app and put it into your Webfolder. You can find the latest FourDAdmin build here: https://github.com/fourctv/fourdadmin/raw/master/distribution/fourDAdmin.zip

Download and unzip that file and drop its contents into your own Webfolder. You can copy the fourDAdmin directory as is, and then open it on your browser by using a URL pointing to your application, like http://localhost:8080/fourDAdmin.

Then you can use the FourDAdmin web app to browse your database, query for records, view individual records, create/update/delete records, view and edit 4D Choice Lists. Using the FourDAdmin app will exercise most of the RESTApi calls and ensure your host methods are working as expected.

Let's get going with Angular

There are a couple options to get going on Angular and 4D. It all depends on your needs and objectives.

You can use any IDE platform or repository you feel comfortable with. My suggestion is VSCode for an IDE and git for your repository needs.

If you're looking for a web and mobile solution, sharing code between both platforms, then one good option is to go with the TeamMaestro, Angular native seed. That seed is perfect for a single repo, sharing code between web and mobile. TeamMaestro is based on Angular CLI and uses NativeScript for the mobile side. Instructions on how to get started with TeamMaestro can be found here.

Angular CLI

If your project is web only, you can go with an Angular CLI solution. Instructions for getting started with Angular CLI and JS44D can be found here.